[英]htaccess rewrite url with multiple parameters in a sub folder
我需要重寫以下網址:
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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.