仅重定向到特定域 [英] Redirect only with specific domain
问题描述
我有一个拥有2个不同域的网站,例如:
I have a website with 2 different domains, for example:
www.example.com
www.example.net
现在,我希望来自 example.com 的每个用户都应重定向到 www.example.de
Now i want, that every user coming from example.com should be redirected to www.example.de
我会尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^.*$ http://example.de/$0 [L,QSA,R=301]
但是现在仍然将来自 example.net 的所有用户重定向到 example.de
But now still all users from example.net get redirected to example.de
我该如何解决,只有 example.com 中的用户被重定向(包括所有子文件夹)。
How can i solve that, that only users from example.com gets redirected (also with all subfolders).
谢谢!
推荐答案
尝试一下-您要匹配example.com(删除!),然后
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]
此外,在调试时,请将 R = 301
更改为 R
,因此您的浏览器不会坚持。当它起作用时,将其更改回 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
这篇关于仅重定向到特定域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!