Reputation: 809
I've got two directives in my htaccess.
RewriteRule ^(it|en|de)/(.*) $2?lng=$1 [L,QSA]
That means: for all url with start with it, en, de set url variables "lng" to $lang
Now, i want that all pages that didn't start with a language code to be redirected to /it:
I try this:
RewriteCond %{REQUEST_URI} !^/(it|en|de)/{0,1}(.*)
RewriteRule ^(.*)$ /it/$1 [R=301,L]
but when i call:
http://HOST/my-page
on url, i get, with a "ERR_TOO_MANY_REDIRECTS":
http://HOST/it/my-page?lng=it&lng=it&{many-others-lng=it}
the word "/it" is added correctly at the beginning of the url, but also infinity "lng=it"
I use "L" flag: this shoud stop processing the rule set.
Any hint?
EDIT: Add my full .htaccess
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(it|en|de)/(.*) $2?lng=$1 [L,QSA]
RewriteRule ^catalogue-men$ views/main/pages/index.cfm?gen=1 [QSA,L]
RewriteCond %{REQUEST_URI} !^/it/
RewriteRule ^(.*)$ /it/$1 [R=301,L]
Upvotes: 1
Views: 424
Reputation: 785256
Just remember that mod_rewrite
runs in loop until there is no rule that fires. You are getting redirect loop because first rule is removing /it/
from start of URI and 301
rule is adding it in front.
THE_REQUEST
instead of REQUEST_URI
/catalogue-men
in your skip conditionThis .htaccess should work for you:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+(?:it|catalogue-men)/ [NC]
RewriteRule ^(.*)$ /it/$1 [R=301,L,NE]
RewriteRule ^(it|en|de)/(.*) $2?lng=$1 [L,QSA]
RewriteRule ^catalogue-men$ views/main/pages/index.cfm?gen=1 [QSA,NC,L]
Upvotes: 1