[英]URL is duplicated in htaccess rewrite URL
我對htaccess重寫規則有點陌生,但遇到了麻煩。 我制定了以下重寫規則:
RewriteRule ^products/(.*)/?$ /single-product.php?product_name=$1 [NC,NS]
因為我想將類似site.com/products/product1
的URL重寫為site.com/single-product.php?product_name=product1
。
問題是當我嘗試在瀏覽器中訪問site.com/products/product1
時,URL變為site.com/products/products/product1
。 如果刷新瀏覽器,它將變成site.com/products/products/products/products/product1
。
作為完整參考,這是我完整的.htaccess
文件:
Options -Multiviews
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^products/(.*)/?$ /single-product.php?product_name=$1 [NC,NS]
我需要怎么做才能防止這種情況發生?
編輯:我在Firefox上進行了測試(我以前在Chrome中進行過測試),但得到了不同的結果。 我嘗試在Firefox上搜索相同的URL site.com/products/product1
,結果為site.com/products/product1/products/product1/
嘗試這個
# Prevent parsing other rules after that (L flag)
RewriteRule ^products/(.*)/?$ /single-product.php?product_name=$1 [NC,NS,L]
要么
# Prevent matching paths with another slash after products
RewriteRule ^products/([^/]*)/?$ /single-product.php?product_name=$1 [NC,NS,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.