[英].htaccess redirecting to 404 error
問題:我想從www.domain.com/index.php?mod=daily
重定向到www.domain.com/daily_rent
從www.domain.com/advert.php?id=11
重定向到www.domain.com/advert/11
可以正常進行以下操作:
RewriteCond %{THE_REQUEST} advert\.php\?id=([0-9]+)\ HTTP/
RewriteRule ^advert\.php$ http://www.domain.com/advert/%1? [R=301,L]
相同的規則
RewriteCond %{THE_REQUEST} index\.php\?mod=daily\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/daily_rent? [R=301,L]
重定向到www.domain.com/daily_rent
並引發404錯誤。 可能是什么原因?
UPD:從www.domain.com/index.php?mod=daily
重定向到www.domain.com/daily_rent
可以正常工作,謝謝anubhava
在那種情況下,另一個問題是,在相似的頁面上,我有多個查詢參數,例如:( www.domain.com/?mod=daily&room=1&area=bstn
所以,我嘗試使用該規則
RewriteCond %{THE_REQUEST} \?mod=daily&room=([0-9]+)&area=([A-Z]+)\ HTTP/
RewriteRule ^$ http://www.domain.com/daily_rent/room/%1/area/%2? [R=301,L]
RewriteRule ^daily_rent/room/([0-9]+)/area/([A-Z]+)/?$ /?mod=daily&room=$1&area=$2 [QSA,L]
這種情況下的解決方案是什么? 謝謝
當然,您肯定希望這樣做-將/daily_rent
重定向到/index.php?mod=daily
嗎? 那將是更常見的用法或mod_rewrite。
RewriteRule ^daily_rent$ /index.php?mod=daily [R=301,L]
您不需要RewriteCond
因為您缺少內部重寫規則。 嘗試以下規則:
RewriteCond %{THE_REQUEST} advert\.php\?id=([0-9]+)\s
RewriteRule ^advert\.php$ /advert/%1? [R=301,L]
RewriteCond %{THE_REQUEST} index\.php\?mod=(daily)\s
RewriteRule ^index\.php$ /%1_rent? [R=301,L]
RewriteRule ^(daily)_rent/?$ /index.php?mod=$1 [QSA,L]
RewriteRule ^advert/([^/]+)/?$ /advert.php?id=$1 [QSA,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.