htaccess: redirect all requests to different domain (without query arguments)

雨燕双飞 提交于 2020-02-20 06:58:32

问题


How can I redirect all requests (irrespective of what page is being requested) on sub.domain.com to newdomain.com? Currently I have

Redirect 301 / http://www.newdomain.com/

When a requests comes in for domain.com/shop/product the redirect goes to newdomain.com/shop/product while it should just go to newdomain.com


回答1:


Use Rewrite:

RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]



回答2:


RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

That will forward any GET requests.



来源:https://stackoverflow.com/questions/3255967/htaccess-redirect-all-requests-to-different-domain-without-query-arguments

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