I want to redirect this way: from www.example.com/link.php?a=1&b=1 to www.example.net/subdirectory/link.php?a=1&b=1
I tried to use this .htaccess which isn't working:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.net/subdirectory$ [L,R=301]
The above redirects www.example.com/link.php?a=1&b=1 to www.example.net/subdirectory/?a=1&b=1, omitting the link.php part.
System is apache2.2 + mod_rewrite running on debian wheezy 64bit. Thanks in advance.
You just put
$
at the end of the RewriteRule, but you'll want the first capture group of your regex (the.*
bit of^(.*)$
). That is fetched with$1
, also mind you'll still need a trailing slash at the end. So, all in all, update your rule to:http://www.example.com/link.php?a=1&b=1
would then be rewritten tohttp://www.example.net/subdirectory/link.php?a=1&b=1