问题
basally I need to redirect
http://www.old-domain.com/news.php?NewsID=30888
to
http://www.new-domain.com/news.php?NewsID=30888
using htaccess however only if the query string is as above. Any other query strings I need to continue to go to
http://www.old-domain.com/news.php?NewsID=whatever_querystring.
So I need to match the 30888 and then redirect to a whole new site including the news.php?NewsID=30888
.
Thanks in advance
回答1:
Put this code in your .htaccess and try;
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^NewsID=30888 [NC]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$ [NC]
RewriteRule ^ http://www.new-domain.com%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
回答2:
You have to test your Query string and the host name:
RewriteCond %{QUERY_STRING} NewsID=30888 [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC]
RewriteRule ^/(.*) http://www.new-domain.com/$1 [L,R]
来源:https://stackoverflow.com/questions/6414180/htaccess-redirect-one-domain-to-another-incliuding-specific-query-string