Reputation: 61
Need a little help with rewrite rule. How do I redirect an url with query to another url with query? Example:
http://example.com/prject/test.php?key=1
redirect to
http://example.com/prject/test.php?id=1
Also
http://example.com/prject/file2.php?key=1
to
http://example.com/prject/file2.php?arg=1
.htaccess file is located in /project/ directory.
Upvotes: 1
Views: 1710
Reputation: 9007
In your /project/.htaccess
file, insert the following:
RewriteEngine On
RewriteBase /project/
# Redirect test.php?key=<number> to test.php?id=<number>
RewriteCond %{QUERY_STRING} key=(\d+)
RewriteRule ^test.php$ test.php?id=%1 [R,L]
# Redirect file2.php?key=<number> to file2.php?arg=<number>
RewriteCond %{QUERY_STRING} key=(\d+)
RewriteRule ^file2.php$ test.php?arg=%1 [R,L]
Upvotes: 2
Reputation: 41219
Try this :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^key=([^&]+) [NC]
RewriteRule ^ http://example2.com/prject/test.php?key=%1 [NC,R,L]
Upvotes: 1