[英]PHP - mod_rewrite clean urls and query strings
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI}/site1 [L,R=301]
RewriteRule ^/site1/catalogue/(\w+)/([0-9]+)$ catalogue.php?category=$1&product_id=$2 [QSA,L]
我在使用某些mod_rewrites時遇到麻煩。 我正在嘗試完成3件事:
1)刪除www。 從網址
2)刪除.php擴展名
3)是否包含涉及$ _GET變量的干凈網址(查詢字符串?)
例如,我想要這個網址:
http://www.domain.com/site1/catalogue.php?category=kitchen&product_id=2
變成這樣:
是的,我的.htaccess文件位於site1文件夾/目錄中。 輸入清除的網址似乎無法正確重定向我。 我要404。 我假設問題是我對查詢字符串的最后重寫規則。
將最后一條規則更改為此:
RewriteRule ^catalogue/(\w+)/([0-9]+)$ catalogue.php?category=$1&product_id=$2 [QSA,L]
從正則表達式匹配項中刪除/site1/
。 還要在RewriteEngine On
之后添加它:
RewriteBase /site1/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.