我需要重写以下网址:
http://localhost/homemarket/products/C1/C2/
到
http://localhost/homemarket/products.php?catergory=C1&sub_category=C2
我尝试遍历stackoverflow,发现了类似的重写规则,但我遇到了以下问题:
.php
添加到我的sub_category查询中)。以下是我的尝试:
# Do not remove this line, otherwise mod_rewrite rules will stop working
Options +MultiViews
RewriteEngine On
RewriteBase /
#Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#Prevent directory listings
Options All -Indexes
#Error Documents
ErrorDocument 404 /homemarket/error.php?404
ErrorDocument 500 /homemarket/error.php?500
#Remove extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ /homemarket/buyers/$1.php [NC,L]
RewriteRule ^products/([^/]*)/([^/]*)/?$ /homemarket/buyers/products.php?category=$1&sub_category=$2 [NC,L]
DirectoryIndex index.php
答案 0 :(得分:1)
您的第一条规则与uris匹配,您需要在规则中排除斜杠,以便它不会与其他规则冲突:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ /homemarket/buyers/$1.php [NC,L]