2012-03-22 96 views
0

这是我的mod_rewrite规则:mod_rewrite的现有目录

RewriteEngine On 
RewriteRule ^([^./]+)/?$ index.php?id=$1 [L] 

这将改写http://www.mysite.com/abc/http://www.mysite.com/index.php?id=abc。但是,我也有一个子目录,我不希望它被重写。所以如果一个目录存在,它应该只使用该目录。如果不是,它将使用重写。如何才能做到这一点?

回答

2

容易馅饼:

RewriteEngine On 
# Make sure it's not a real directory 
RewriteCond %{REQUEST_FILENAME} !-d 
# Make sure it's not a real file 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^./]+)/?$ index.php?id=$1 [L] 

哎对了,我花了2秒找到了答案:2秒=键入时间“重写规则文件不存在”

+0

你真棒:D – Patrick 2012-03-22 08:13:09

+0

这是我的荣幸! – 2012-03-22 08:17:08

0

不要忘了包括下面这个RewriteEngine On

RewriteBase /yourdirectory