1

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.

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

Comments

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.