I am new to WordPress and want to redirect some specific traffic. Here’s an example –
-
A user from a different website clicks on a link with url
http://mywordpresssite.com/redirect?url=http://amazon.in/blablabla
-
I want my website to redirect the request to
http://amazon.in/blablabla
or whatever be the url in the querystring without loading anypage of my website. - My website should function normally for all other requests.
I tried with htaccess and came up with this –
RewriteCond %{QUERY_STRING} (?:^|&)url=([^&]+)(?:&|$) [NC]
RewriteRule ^(.*)$ %1 [R=302,L]
But the RewriteRule results in http://mywordpresssite.com/http://amazon.in/blablabla?url=http://amazon.in/blablabla
which is wrong.
I am new to htaccess and would be grateful for any help.
Try the following in .htaccess in the root of your site. Note that this should go before your existing WordPress mod_rewrite rules but after
RewriteEngine On
.The
%1
refers to the first parenthesised subpattern in theRewriteCond
directive (ie. everything after the “url=”).The
QSD
flag (Apache 2.4+) removes the query string from the original request.Before Apache 2.4 you would need to change the
RewriteRule
to read (note the additional?
at the end of the substitution):