.htaccess redirect one domain to another incliuding specific query string

和自甴很熟 提交于 2019-12-11 07:04:01

问题


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 tohttp://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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!