RewriteEngine和类别链接

时间:2013-07-14 18:15:33

标签: .htaccess

我正在尝试做类似

的事情
business/index.html
business/
business

打开categories.php?prefix=$1

我用过

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

它工作得很好,但是当打开/管理它的真实文件夹时,它将其作为一个类别读取 我怎么能排除那个

2 个答案:

答案 0 :(得分:1)

这将查看路径是以admin还是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]

答案 1 :(得分:0)

你可以这样做:

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

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