mod_rewrite对除特定目录之外的一个文件的所有请求

时间:2014-01-18 18:35:45

标签: apache .htaccess mod-rewrite

我有一个网站,我想将我网站上的所有请求重写为一个页面。但是,如果有特定子目录的请求,我希望这些请求照常处理。

这是我目前的.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^lib/(.*)$ lib/$1 [END]
RewriteRule ^scripts/(.*)$ scripts/$1 [END]
RewriteRule ^styles/(.*)$ styles/$1 [END]
RewriteRule ^tpl/(.*)$ tpl/$1 [END]
RewriteRule ^services/(\w+)$ services/$1.php [END]
RewriteRule ^services/(\w+)/(\w+)$ services/$1.php?id=$2 [END]
RewriteRule ^.*$ index.html [END]
</IfModule>

如果我转到site/scripts/ascript.js它可行:脚本已发送。除lib规则外,所有规则都有效。

如果我转到site/lib/something.js它不起作用,则会传递index.html。

为什么lib无效?

1 个答案:

答案 0 :(得分:0)

你的规则如下:

RewriteEngine On
RewriteBase /

RewriteRule ^lib/(.*)$ lib/$1 [END]
RewriteRule ^scripts/(.*)$ scripts/$1 [END]
RewriteRule ^styles/(.*)$ styles/$1 [END]
RewriteRule ^tpl/(.*)$ tpl/$1 [END]
RewriteRule ^services/(\w+)$ services/$1.php [END]
RewriteRule ^services/(\w+)/(\w+)$ services/$1.php?id=$2 [END]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ index.html [END]