0

所以我在 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
4

1 回答 1

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

这样,如果请求 url 与单词“blog”不匹配,则将应用所有后续规则。

于 2012-07-10T15:41:11.993 回答