skip to Main Content

I have two old domains http://example1.com (English) and http://example2.com (French) and would like them to redirect to my new domain such as:

http://example1.com => http://newdomain.com/en/

http://example2.com => http://newdomain.com/fr/

Also I want to make sure the permalinks remain the same after redirecting as well.

E.g. http://example1.com/test.html => http://newdomain.com/en/test.html

My Code:

The below code fails to maintain the permalinks, also I am not sure how to add the french domain in the check.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example1.com$
RewriteRule (.*)$ http://www.newdomain.com/en/$1 [R=301,L]
</IfModule>

2

Answers


  1. The following should work:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} example1.com$
    RewriteRule (.*) http://www.example.com/en/$1 [R=301,L]
    
    RewriteCond %{HTTP_HOST} example2.com$
    RewriteRule (.*) http://www.example.com/fr/$1 [R=301,L]
    

    As for keeping the permalinks, I don’t think you can do it here, you’ll have to do it in the new domain’s .htaccess.

    What do you use for translation ? Does it accept query parameters or is able to parse the uri by itself ?

    Login or Signup to reply.
  2. Have it like this:

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

    Make sure to keep these rules as your top rules before other rules and you test in a new browser to avoid old browser cache.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search