0

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

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

但它也会重写所有包含 html 的文件(如 jquery、css 等)的路径...所以,当我尝试访问时domain.com/templates/js/jquery.min.js- 我的 php 脚本会抛出异常,因为它没有找到所需的参数。我也尝试添加 [az] 但它没有帮助。

4

2 回答 2

0

尝试以下操作:

RewriteRule ^([a-z0-9]*)$ index.php?q=$1 [L,QSA]
于 2012-09-24T16:52:11.193 回答
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。

于 2012-09-24T16:52:18.220 回答