markratledge
markratledge

Reputation: 17561

How to .htaccess redirect this URL with a query string?

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

Upvotes: 1

Views: 1427

Answers (2)

anubhava
anubhava

Reputation: 786081

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]

Upvotes: 2

Gumbo
Gumbo

Reputation: 655735

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]

Upvotes: 0

Related Questions