1

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.

Tutul
  • 892
  • 6
  • 20

1 Answers1

1

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:

RewriteRule ^(.*)$ http://www.example.net/subdirectory/$1 [L,R=301]

http://www.example.com/link.php?a=1&b=1 would then be rewritten to http://www.example.net/subdirectory/link.php?a=1&b=1

Oldskool
  • 2,005
  • 1
  • 16
  • 26