2

I want to get rid of some query string on my whole website (explicitly facebook shared/like query which usually begin with fb_action).

I thought about using .htaccess to do that.

I want this: Link 1)

http://example.com/documents/de_desmarais_en_sirois?fb_action_ids=10151430962018298&fb_action_types=og.likes&fb_source=timeline_og&action_object_map={%2210151430962018298%22%3A157643874359578}&action_type_map={%2210151430962018298%22%3A%22og.likes%22}&action_ref_map=[]

to look like: Link 2)

http://example.com/documents/de_desmarais_en_sirois

In my .htaccess, I added:

RewriteCond %{QUERY_STRING} fb_action
RewriteRule ^(.*) /$1? [R=301,L]

But, when I go on the original link, I am directed to my root folder example.com/pages.php, but I want to keep the first part of the URL which is example.com/documents/de_desmarais_en_sirois. I don't want to go to my root.

What should I modify/do?

1 Answer 1

2

I assume you've added those rules to the htaccess file in the /documents/ directory?

You'll need to remove the leading slash in your rule's target and add a rewrite base:

RewriteBase /documents/

RewriteCond %{QUERY_STRING} fb_action
RewriteRule ^(.*) $1? [R=301,L]

The query string match could be improved a bit though:

RewriteCond %{QUERY_STRING} (.*)(^|&)fb_[^&]+(.*)$
RewriteRule ^(.*) $1?%1%2 [R=301,L]
RewriteCond %{QUERY_STRING} (.*)(^|&)action_[^&]+(.*)$
RewriteRule ^(.*) $1?%1%2 [R=301,L]

To remove only the facebook query string parameters, if you have other parameters that you want to preserve.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, Thank you for your help, There is no /document/ directory since everything is rendered dynamically via PHP and mySQL. I use the URL to call specific data in my mySQL database. I can't use RewriteBase. RewriteBase is redirecting all my user to /document/ and I don't want that. I thought that it would be easier to strip a particular query string from the URL with apache .htaccess, but more I think about it, more I think I'm going to strip the query string via PHP.
@DominicD It is easy, what you had pretty much does that. But apparently you have another rule or something somewhere that is redirecting to page.php
Oh, thanks. It's true. When I delete the redirection to "pages.php", the query string is stripped correctly, and i see the good url But, I need that redirection to pages.php... I will need to think about what I will do.
I succeeded. I placed the query string redirection before the redirection to pages.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.