Redirect only with specific domain

六月ゝ 毕业季﹏ 提交于 2020-01-03 17:09:24

问题


I have a website with 2 different domains, for example:

www.example.com www.example.net

Now i want, that every user coming from example.com should be redirected to www.example.de

Ill tried:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^.*$ http://example.de/$0 [L,QSA,R=301]

But now still all users from example.net get redirected to example.de

How can i solve that, that only users from example.com gets redirected (also with all subfolders).

Thanks!


回答1:


Try this - you want to match example.com (remove the !), and it's clearer to capture the incoming url into $1.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ http://example.de/$1 [L,QSA,R=301]

Also, while debugging, change the R=301 to R, so your browser doesn't "stick" with an old rule. When it works, change it back to R=301



来源:https://stackoverflow.com/questions/31145847/redirect-only-with-specific-domain

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