簡體   English   中英

.htaccess-無限循環重定向,在本地工作正常

[英].htaccess - infinite loop redirect, works fine locally

我希望你能幫我一些忙。 我的網站根目錄上有以下htaccess。 這個想法是,只要您輸入[mywebsite] / [country_code],您就會被重定向到[mywebsite] /teaser.php?country= [country_code]。 但是,當我將其上傳到我的網絡服務器時,它進入了[mywebsite] / [country_code] / [country_code] / [country_code] / etc等無限循環...您能告訴我我在做什么錯嗎?

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^cl\/*$ teaser.php?country=cl
RewriteRule ^ar\/*$ teaser.php?country=ar 
RewriteRule ^br\/*$ teaser.php?country=br 
RewriteRule ^bo\/*$ teaser.php?country=bo 
RewriteRule ^co\/*$ teaser.php?country=co 
RewriteRule ^cl\/*$ teaser.php?country=cl 
RewriteRule ^la-ec\/*$ teaser.php?country=la-ec
RewriteRule ^py\/*$ teaser.php?country=py 
RewriteRule ^pe\/*$ teaser.php?country=pe 
RewriteRule ^ve\/*$ teaser.php?country=ve 
RewriteRule ^cr\/*$ teaser.php?country=cr 
RewriteRule ^cu\/*$ teaser.php?country=cu 
RewriteRule ^mx\/*$ teaser.php?country=mx 
RewriteRule ^ni\/*$ teaser.php?country=ni 
RewriteRule ^pa\/*$ teaser.php?country=pa 
RewriteRule ^sv\/*$ teaser.php?country=sv 
RewriteRule ^gt\/*$ teaser.php?country=gt 
RewriteRule ^ht\/*$ teaser.php?country=ht 
RewriteRule ^hn\/*$ teaser.php?country=hn 
RewriteRule ^do\/*$ teaser.php?country=do 
RewriteRule ^uy\/*$ teaser.php?country=uy 

謝謝!

您沒有那么多規則。 只需使用一個簡單的正則表達式將所有規則組合為一個規則並重新測試:

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-z]{2}(?:-[a-z]{2})?)/?$ teaser.php?country=$1 [L,QSA,NC]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM