繁体   English   中英

如何使用 htaccess 将多个域重定向到除 1 个目录之外的另一个域?

[英]How to redirect multiple domains to another domain except 1 directory using htaccess?

我正在尝试将多个域重定向到一个域(工作正常),但我希望一个目录不重定向或更改主域 url。

这是我的 .htaccess 代码,它工作正常,直到这里

这个正在工作

<pre>
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.com$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.net$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.org$  [OR]
    RewriteCond %{HTTP_HOST}    ^domain.info$ [OR]
    RewriteCond %{HTTP_HOST}    !^www.domain.info
    RewriteRule (.*)    http://www.domain.info/$1   [R=301,L]
</pre>

但是当我尝试通过以下方式停止重定向一个特定目录时

完整代码

<pre>
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.com$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.net$  [OR]
    RewriteCond %{HTTP_HOST}    ^http(s)?://(www.)?domain.org$  [OR]
    RewriteCond %{HTTP_HOST}    ^domain.info$        [OR]
    RewriteCond %{HTTP_HOST}    !^www.domain.info   [OR]
    RewriteCond %{REQUEST_URI}  !^/no_redirect_dir/
    RewriteRule (.*)    http://www.domain.info/$1   [R=301,L]
</pre>

一切都停止工作:(出现错误,页面未正确重定向。

导致错误的额外代码

<pre>
    RewriteCond %{HTTP_HOST}    !^www.domain.info   [OR]
    RewriteCond %{REQUEST_URI}  !^/no_redirect_dir/
</pre>

任何帮助将不胜感激。

谢谢你!

像这样写你的 .htaccess:

RewriteCond %{HTTP_HOST} (www\.)?domain\.(org|net|com)$ [NC]
RewriteCond %{REQUEST_URI} !^/*no_redirect_dir/ [NC]
RewriteRule ^(.*)$ http://www.domain.info/$1 [R=301,L]

HTTP_HOST 变量只有域名,没有 http/https 信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM