Apache 301 redirect rewrite / to /en and keep /fr to /fr keeping all passed variables

I have a bilingual WordPress site that I am changing the domain for and the following redirect works great.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^newdomain.com$
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

The problem is I would like to have

Read More
olddomain.com/one/two/three 

to redirect to

newdomain.com/en/one/two/three 

but keep

olddomain.com/fr/one/two/three

redirecting to

newdomain.com/fr/one/two/three

Related posts

Leave a Reply

1 comment

  1. You can place this rule just below RewriteBase line in your main WP .htaccess:

    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteRule ^en/ http://newdomain.com%{REQUEST_URI} [L,NE,R=301]
    
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteRule !^(en|fr)/ http://newdomain.com/fr%{REQUEST_URI} [L,NE,R=301]