2017-02-21 16 views
0

私は何かを手伝ってくれることを望んでいました。私は私のウェブサイトのルートに次のhtaccessを持っています。 [mywebsite]/[country_code]と入力すると、[mywebsite] /teaser.php?country= [country_code] にリダイレクトされます。私はそれを自分のApache上でローカルにテストすると完全に動作します。私のウェブサーバーにアップロードすると、[mywebsite]/[country_code]/[country_code]/[country_code]/etc ...の無限ループに入ります。 ここで間違っていることを教えてもらえますか?.htaccess - 無限ループリダイレクト、ローカルで正常に動作します

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 

ありがとうございます!

答えて

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] 
+0

事は、私が確認する必要がありますということである国コードの特定のセットのために、この作品ではなく、2つの文字の組み合わせについて。しかし、ありがとう! –

+0

リンクが 'domain.com/xy'のようになるのはなぜですか?リンクは 'domain.com/pa'や' domain.com/co'のような既知の国コードでのみ作成されます。 – anubhava

+0

私はリンクを作成していません。それはアイディアです。あなたがパラメータとして渡す国によって異なる行動をします。有効な国コードを入力するとその国のティーザーに行きますが、2文字のランダムな組み合わせを入力すると、404がスローされ、teaser.phpへのリダイレクトは行われません。 –

関連する問題