1

While using a WordPress maintenance plugin, I ended up with this query string URL that I now need to redirect to root when the site goes live.

http://mydomain.com/maintenance/?req=http%3A%2F%mydomain.com%2F

What will redirect that URL to simply http://mydomain.com?

I've tried both of these:

Redirect 301 "http://mydomain.com/maintenance/?req=http://mydomain.com/" http://mydomain.com

Redirect 301 "http://mydomain.com/maintenance/?req=http%3A%2F%mydomain.com%2f" http://mydomain.com
0

2 Answers 2

2

Put these lines in your .htaccess file:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} req=http%3A%2F%2F(.+)%2F [OR] 
RewriteCond %{QUERY_STRING} req=http://([^&]+)(&|$) [NC]
RewriteRule ^maintenance/?$ http://%1? [L,R,NC,NE]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, works great! How would I do a redirect from the original string to a page like mydomain.com/update/ (that shows a link to mydomain.com) so I can advise users to update bookmarks after they click and go to mydomain.com?
You mean redirecting URI /maintenance/?req=http%3A%2F%2Fmydomain.com%2F to http://mydomain.com/update ? That can be simple done by having last line of above rule like RewriteRule ^maintenance/?$ http://%1/update/? [L,R,NC,NE]
0

Redirect does only work with the URL path. You need to use the real mod_rewrite to look at the query:

RewriteEngine on
RewriteCond %{QUERY_STRING} =req=http://example.com/
RewriteRule ^maintenance/$ /? [L,R=301]

1 Comment

Thanks, but couldn't get this to work; it was in the correct place, after RewriteEngine on and before the WP rewrite block.

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.