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?
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.
Related
So currently I have URLs that looks like this:
http://localhost/?v=register
http://localhost/?v=profile&u=thatgerhard
I want the above to look like this:
http://localhost/register/ (without trailing /)
http://localhost/profile/thatgerhard/ (without trailing /)
I spent a ton of time trying to get this to work even though it seems like it should be a simple fix.
This is what I have atm:
RewriteBase /
RewriteEngine On
RewriteRule ^((.)*)$ /?v=$1&p=$
I would ideally like this to be dynamic so that if you do ?v=foo it will automatically do /foo/ without adding "foo" to the htaccess file.
Any help or direction will be greatly appreciated. :)
You should use RewriteCond Directive and RewriteCond backreferences. The %1 backreference matches the query string parameter v, the %2 backreference matches the query string parameter u. The RewriteRule redirects the request permanently and discard the query string entirely.
RewriteCond %{QUERY_STRING} ^v=([^&]*)$ [NC]
RewriteRule ^/?$ /%1/? [R=301,L]
RewriteCond %{QUERY_STRING} ^v=([^&]*)&u=([^&]*)$ [NC]
RewriteRule ^/?$ /%1/%2/? [R=301,L]
I have dozens of redirects from an old page e.g. index.php?mode=1,2,3,0 and I want to get rid of all GET Params because the new page is anyways just plain html.
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} mode=17,0,0,0,0$
RewriteRule (.*) /big-mamas-house/ [R=301,L]
I thought removing (.*) would already do the trick but then the rule is not applied anymore according to:
http://htaccess.madewithlove.be/
Your rule can simplified to:
RewriteCond %{QUERY_STRING} ^mode=17,0,0,0,0$
RewriteRule ^index\.php$ /big-mamas-house/? [R=301,L,NC]
? in the end is needed to strip off any previous query string.
How can I redirect url's ending with catalogue.php, for example
http://www.example.com/catalogue.php
to
http://www.example.com/all
Not affecting url's like http://www.example.com/catalogue.php?title=titleName&page=2
Tried the following code:
RewriteCond %{REQUEST_URI} /catalogue.php
RewriteRule ^(.*)$ www.example.com/all/$1 [R=301,L]
Try this:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^catalogue\.php$ /all [R=301,L]
You will be redirected only if requesting /catalogue.php, wthout any query string parameters.
If you need to specify them, you can change the first line to something similar to:
RewriteCond %{QUERY_STRING} !title|titleName|page
Here redirect will be done only if none of title, titleName, page parameters specified.
Added
If catalogue.php may be in subfolder, use:
RewriteRule (^|/)catalogue\.php$ /all [R=301,L]
You can read more about regular expressions in order to understand how it works.
I am trying to make:
http://www.specialisedorthoticservices.co.uk/image.php?object_type=detailed&image_id=140&window=popup
become this:
http://www.specialisedorthoticservices.co.uk
The result of the query no longer exists and the re-direct doesn't seem to work see code below:
RewriteCond %{REQUEST_URI} ^/image\.php$
RewriteCond %{QUERY_STRING} ^object_type=detailed&image_id=140&window=popup$
RewriteRule ^(.*)$ http://www.specialisedorthoticservices.co.uk [R=301,L]
Remove the slash before image.php. In fact, why not just shorten it? To not append the query string you need a terminating question mark like so
RewriteEngine On
RewriteCond %{QUERY_STRING} ^object_type=detailed&image_id=140&window=popup$
RewriteRule ^image\.php$ /? [R=301,L]
Bit of an odd question, but I'd like to have a query string set on all of my URLs. If the parameter isn't set (or is empty), then I'd like to redirect to include a default.
For example:
example.com would need to requrect to example.com?param=a
example.com?param would also need to redirect to example.com?param=a
If the param is set and is part of a list of known values, then it should carry on as normal:
example.com?param=(a|b|c|d) would go to the respective page a,b,c or d
Some pages of the site use other parameters to sort and paginate, so the rules cannot assume that this is the only query string.
I've tried a couple of things, but kept getting stuck in a redirect loop. This is trying to set the default param:
RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&)
RewriteRule ^(.*)$ /index.php?rq=$1¶m=a [L,QSA]
The main CMS rewrite rule is:
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]
Any help would be great!
RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&)
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ $1?%{QUERY_STRING}¶m=a [L]
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]