简体   繁体   English

多语言网站的URL重写问题

[英]Problem with url-rewriting for a multi-language website

I have tried to set somes url rewriting rules for my multi-langage website. 我试图为我的多语言网站设置一些URL重写规则。 It was working, and I wanted to apply some corrections, and now it is not working anymore. 它正在工作,我想进行一些更正,现在它不再工作。

When I tried this url : http://mywebsite.fr/fr/ , the browser changes the url for http://mywebsite.fr/fr/?lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr 当我尝试以下网址: http : //mywebsite.fr/fr/时 ,浏览器将更改http://mywebsite.fr/fr/?lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang=fr&lang= FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR&LANG = FR

Here is the code: 这是代码:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(fr|en|nl)/$ index.php?lang=$1&%{QUERY_STRING} [L]

I said to myself that kind of bug couldn't come from url-writing, so in my php code I have put an "return false" as the very beginning of the page, the problem still occurs whit a white page... 我对自己说,这种错误不是源于URL编写,因此在我的php代码中,我将“ return false”作为页面的开头,但是在白页中仍然会出现问题...

Also, if I disable all the url-rewriting rules, I recevied an apache error "Not found"... 另外,如果我禁用所有的url重写规则,则会收到apache错误“未找到” ...

I have also tried to restart Apache, same problem... 我也尝试过重新启动Apache,同样的问题...

Anybody have an idea ? 有人有主意吗? Thanks ! 谢谢 !

What you see is a typical rewrite loop. 您将看到一个典型的重写循环。 The cause is that you unconditionally rewrite, regardless whether the goal of rewriting has already been achieved, so whether rewriting has already been performed before. 原因是您无条件地进行了重写,而不管重写目标是否已经实现,因此之前是否已经执行过重写。

You can get around that using a condition: 您可以使用条件来解决此问题:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} !^lang=
RewriteRule ^/?(fr|en|nl)/?$ /index.php?lang=$1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM