0

我正在尝试做类似的事情

business/index.html
business/
business

打开categories.php?prefix=$1

我习惯了

RewriteRule ^([A-Za-z0-9-]+)/?(index.html)?$ categories.php?prefix=$1 [QSA,L]

它工作得很好,但是当打开 /admin 它是一个真正的文件夹时,它将它作为一个类别读取,我如何排除它

4

2 回答 2

1

这将查看路径是否以adminor开头images。如果是这样,则该规则将不适用。如果不是(即如果它以其他任何内容开头),则该规则将适用:

# Only apply to files that exist (uncomment to use):
#RewriteCond %{REQUEST_FILENAME} -f
# Only apply if the request is NOT for a directory (uncomment to use):
#RewriteCond %{REQUEST_FILENAME} !-d
# Only apply when the requested URI begins with admin or images (Not Case-sensitive):
RewriteCond %{REQUEST_URI} !^(/[admin|images]/) [NC]
# If all conditions are met, apply the following rule:
RewriteRule ^([A-Za-z0-9-]+)/?(index.html)?$ categories.php?prefix=$1 [QSA,L]
于 2013-07-14T18:20:40.437 回答
0

你可以这样做 :

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-]+)/?(index.html)?$ categories.php?prefix=$1 [QSA,L]

除非打开真正的文件夹或文件,否则这将重写所有 url。

于 2013-07-14T18:33:08.833 回答