友情网址仅供网址使用

时间:2012-09-24 16:46:30

标签: apache mod-rewrite

对不好的标题名称抱歉...问题是我使用标准重写,如:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

但它也重写了所有html包含文件的路径,如jquery,css等...所以,当我尝试到达domain.com/templates/js/jquery.min.js时 - 我的php脚本会抛出exeption,因为它找不到所需的参数。我也尝试添加[a-z],但没有帮助。

2 个答案:

答案 0 :(得分:0)

尝试以下方法:

RewriteRule ^([a-z0-9]*)$ index.php?q=$1 [L,QSA]

答案 1 :(得分:0)

您需要添加一些条件来排除合法请求:

# if the request isn't for an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# if the request isn't for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# then rewrite the entire request to index.php
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

由于/templates/js/jquery.min.js是对现有文件的请求,因此第一个条件将失败,请求将不会被重写为index.php。

相关问题