繁体   English   中英

Apache htaccess mod重写

[英]Apache htaccess mod rewrite

因此,我的htacces文件遇到一些问题,试图执行一些重写条件。 我正在尝试做的是:

有指向该Web文件夹的多个域。 如果域是example.com以外的任何内容,则我希望它重写为example.com,除非-路径为/ path

现在一切正常,除非您访问www.otherexample.com/path

它达到了最后一条规则,并将URL更改为http://dev.otherexample.com/index.php?qs-rewrite=path并导致重定向循环。

这是整个htaccess文件

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /

RewriteCond %{HTTP_HOST}          !example\.com$ [NC]
RewriteCond %{REQUEST_URI}        !^/path [NC]
RewriteRule ^.*$                  http://dev.example.com%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_URI}        ^(.*)//(.*)$
RewriteRule .                     %1/%2 [R=301,L]

RewriteCond %{REQUEST_FILENAME}   !-f
RewriteCond %{REQUEST_FILENAME}   !-d
RewriteRule ^.*$                  index.php?qs-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>

这应该是您完整的.htaccess:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST}          !example\.com$ [NC]
RewriteCond %{REQUEST_URI}        !^/path [NC]
RewriteCond %{QUERY_STRING}       !qs-rewrite=[^&]+ [NC]
RewriteRule ^                     http://dev.example.com%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_URI}        ^(.*)//(.*)$
RewriteRule .                     /%1/%2 [R=301,L]

RewriteCond %{REQUEST_FILENAME}   !-f
RewriteCond %{REQUEST_FILENAME}   !-d
RewriteRule ^                     /index.php?qs-rewrite=%{REQUEST_URI} [L,QSA]
</IfModule>

暂无
暂无

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

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