Jump to content

Going mad with infinite loop and RewriteCond, need help.


Racoon

Recommended Posts

I want to redirect users to my home page if they enter any URL not starting with 'en' or 'fr'. I've spent hours trying to make this work but this proves too tough for my fragile newbie brain. Currently, if I try to go to

http://mysite.com/fr/produits/

Firefox tells me that the redirect will never complete.

 

Here's what I want:

http://mysite.com/en/whatever/ ==> rewrite as /whatever/index.php?lang=en

http://mysite.com/fr/whatever/ ==> rewrite as /whatever/index.php?lang=fr

 

http://mysite.com/jp/whatever/ ==> 301 redirect to /fr/accueil/

http://mysite.com/whatever/ ==> 301 redirect to /fr/accueil/

 

Here's my current htaccess. See inline comments for details.

 

Options +FollowSymLinks

RewriteEngine On

RewriteBase /

 

# Require no www

RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]

RewriteRule ^(.*)$ http://mysite.com/$1 [R=301]

 

# Redirect from root to /fr/accueil/, the URL for the default home page

RewriteRule ^/$ http://mysite.com/fr/accueil/ [NC,R=302]

 

# Rewrite language path fragment (/fr or /en) as a parameter

RewriteRule ^fr/accueil/$ /accueil/index.php?lang=fr [QSA,NC]

RewriteRule ^en/home/$ /accueil/index.php?lang=en [QSA,NC]

RewriteRule ^fr/produits/$ /produits/index.php?lang=fr [QSA,NC]

RewriteRule ^en/products/$ /produits/index.php?lang=en [QSA,NC]

 

# I'm aware that the rules in this htaccess are re-examined each

# time a rewrite is issued. So the 'fr/accueil/' I'm redirecting to

# will itself be rewritten as /accueil/index.php?lang=fr. That is

# why I'm providing 3 conditions:

# If URI does not start with 'en' AND

# If URI does not start with 'fr' AND

# If QUERY_STRING is not exactly 'lang'

RewriteCond %{REQUEST_URI} !^en/.*$

RewriteCond %{REQUEST_URI} !^fr/.*$

RewriteCond %{QUERY_STRING} !^lang$

RewriteRule ^.*$ fr/accueil/ [NC,R=301]

 

Please put me out of my misery. Cheers!

Link to comment
Share on other sites

RewriteRule ^fr/accueil/$ /accueil/index.php?lang=fr [QSA,NC] 

 

... and ...

 

RewriteCond %{REQUEST_URI} !^en/.*$
RewriteCond %{REQUEST_URI} !^fr/.*$
RewriteCond %{QUERY_STRING} !^lang$
RewriteRule ^.*$ fr/accueil/ [NC,R=301]

 

Will cause a loop. The second redirects the URL to a link that matches the URL to be written in the first. But since you are checking !^lang$ you are only comparing QUERY_STRING values that are exactly 'lang', whereas you are sending to 'lang=fr'. Remove the dollar sign from that RewriteCond or at the .* as you have done in the others.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.