Endless Redirect Loop by htaccess for multi language websites
by Subramanian[ Edit ] 2014-01-03 14:38:34
Endless Redirect Loop by htaccess for multi language websites:
When we change our site to multi language support then we need to redirect all our site link to multi language support links like
www.worddrawing.com/tags.php to
www.worddrawing.com/ta/tags.php.
The following htaccess rule is used to automatically do the above process. and
www.worddrawing.com/ta/tags.php link pass lang variable to identify the what language is used like
ta,en,de etc.., it avoid 404 page redirect when we use old url with ta/,en/,de/...
The htaccess rule is
RewriteBase /
# empty url -> redirect to ta/
RewriteCond %{QUERY_STRING} !lang=(ta)
RewriteRule ^$ ta/ [R=301,L]
# url is ONLY '/ta' -> redirect to /ta/ (adding slash)
RewriteRule ^(ta)$ $1/ [R=301,L]
# now all urls have ta/ -> parse them
RewriteRule ^(ta)/(.*)$ $2?lang=$1&%{query_STRING} [L]
Note : If u want to use it to multi language then consider below one.
RewriteBase /
# empty url -> redirect to ta/
RewriteCond %{QUERY_STRING} !lang=(ta|en|es)
RewriteRule ^$ ta/ [R=301,L]
RewriteRule ^$ en/ [R=301,L]
RewriteRule ^$ es/ [R=301,L]
# url is ONLY '/ta' -> redirect to /ta/ (adding slash)
RewriteRule ^(ta|en|es)$ $1/ [R=301,L]
# now all urls have ta/ -> parse them
RewriteRule ^(ta|en|es)/(.*)$ $2?lang=$1&%{query_STRING} [L]