Balconsky
Balconsky

Reputation: 2244

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]

</IfModule>

# END WordPress

Upvotes: 1

Views: 576

Answers (1)

Ravi Hirani
Ravi Hirani

Reputation: 6539

Try below rule:-

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

OR

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

Hope it will work for you :)

Upvotes: 2

Related Questions