使用mod_rewrite忽略目录

时间:2012-07-10 15:06:15

标签: mod-rewrite

所以我在blog /

上有一个博客

我想阻止yii(框架)重写blog /目录中的url。

我如何使用modrewrite做到这一点?

这是我的.htaccess文件:

RewriteEngine on
#RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
#RewriteCond %{HTTPS}s ^on(s)|
#RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

1 个答案:

答案 0 :(得分:1)

添加以下行:

RewriteCond %{REQUEST_URI} !blog

例如:

RewriteEngine on
RewriteCond %{REQUEST_URI} !blog
#RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
#RewriteCond %{HTTPS}s ^on(s)|
#RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

这样,如果请求网址与“博客”一词不匹配,则会应用所有后续规则。