简体   繁体   中英

Problem with url-rewriting for a multi-language website

I have tried to set somes url rewriting rules for my multi-langage website. 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

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...

Also, if I disable all the url-rewriting rules, I recevied an apache error "Not found"...

I have also tried to restart Apache, same problem...

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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