Reputation: 3202
I used to have a query string for handling mobile pages. Now the site is responsive it doesn't need it and I need to do 301 redirects let google know.
so
http://www.example.com/aaa/bbb?fromMobile=true should become http://www.example.com/aaa/bbb
and
http://www.example.com/aaa?fromMobile=true should become http://www.example.com/bbb
and
http://www.example.com?fromMobile=true should become http://www.example.com
etc
I have:
RewriteCond %{QUERY_STRING} ^(?)fromMobile=true$ [NC]
RewriteRule (.*) /$1?%1&%2 [R=301,L]
But this redirects:
http://www.example.com?fromMobile=true to http://www.example.com?
How can I get rid of the trailing question mark? I've tried a bunch of things without joy.
Upvotes: 1
Views: 96
Reputation: 786349
You can use:
RewriteCond %{QUERY_STRING} ^fromMobile=true$ [NC]
RewriteRule (.*) /$1? [R=301,L]
This is assuming there is no other query parameter besides fromMobile=true
.
If there is a chance of other query parameters also then use:
RewriteCond %{QUERY_STRING} ^(.+?&)?fromMobile=true(?:&(.*))?$ [NC]
RewriteRule (.*) /$1?%1%2 [R=301,L]
Upvotes: 1