htaccess没有像我预期的那样工作

时间:2014-03-25 15:44:37

标签: regex apache .htaccess mod-rewrite

我有以下脚本:

Options +FollowSymLinks
RewriteEngine On

# PATH
RewriteBase /bbv/

# ERROR RULE
ErrorDocument 404 /bbv/404.php

# WORKS
RewriteRule ^home$ index.php
RewriteRule ^contact$ contact.php
RewriteRule ^(.*)\.html$ template_cat.php?cat=$1 [L]

# THIS DOES NOT WORK
RewriteRule ^(.*)\(.*)-(.*)$ template_prod.php?cat=$1&prod=$2&id=$3 [L] 
RewriteRule ^(.*)$ template_cat.php?cat=$1 [L]

我希望如下: localhost / bbv / category localhost / bbv / category / product-id < / em>的

错误在哪里? TX。

1 个答案:

答案 0 :(得分:2)

使用此代码:

# ERROR RULE
ErrorDocument 404 /bbv/404.php    
Options +FollowSymLinks
RewriteEngine On    
# PATH
RewriteBase /bbv/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# WORKS
RewriteRule ^home$ index.php [L]
RewriteRule ^contact$ contact.php [L]
RewriteRule ^([^.]+)\.html$ template_cat.php?cat=$1 [L,QSA]

RewriteRule ^([^/]+)/([^-]+)-(.+)$ template_prod.php?cat=$1&prod=$2&id=$3 [L,QSA] 
RewriteRule ^(.+)$ template_cat.php?cat=$1 [L,QSA]