我需要重写以下网址:
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
您的第一个规则与两个uri都匹配,您需要在规则中排除斜杠,以使其与其他规则不冲突:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ /homemarket/buyers/$1.php [NC,L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句