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

时间:2017-02-21 01:01:41

标签: php apache .htaccess webserver

我希望你能帮助我。我在我的网站的根目录上有以下htaccess。这个想法是,无论何时输入[mywebsite] / [country_code],您都会被重定向到[mywebsite] /teaser.php?country= [country_code] 当我在我的apache上本地测试时,它完美地工作;但是当我将它上传到我的网络服务器时,它会进入[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 

谢谢!

1 个答案:

答案 0 :(得分:0)

你没有这么多规则。只需使用一个简单的正则表达式将所有规则组合成一个规则并重新测试:

RewriteEngine on

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