Home Ask Login Register

Developers Planet

Your answer is one click away!

Balconsky February 2016

301 redirect in htacess for default language

I have wordpress site with qtranslate plugin. Russian language is default (ru). I have pages: http://example.com/en/xxx http://example.com/ru/xxx (302 redirect to http://example.com/xxx) http://example.com/xxx

I need to create 301 redirect from http://example.com/ru/xxx to http://example.com/xxx

I tried to write rule in htacess for redirection, but I got redirect loop:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://example.com.ua/ [R=301,L]
RewriteBase /

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://example.com.ua/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example\.com.ua$ [NC]
RewriteRule ^(.*)$ http://example.com.ua/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/ru(/|$)
RewriteRule ^(.*)$ /$1 [R=301]


# END WordPress


Ravi Hirani February 2016

Try below rule:-

    RewriteEngine on    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ /ru/$1 [NC,L,QSA]


    RewriteEngine On
    RewriteRule ^ru/(.*)$ /$1 [L,R=301,QSA]

Hope it will work for you :)

Post Status

Asked in February 2016
Viewed 1,390 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life