Search code examples
.htaccessmod-rewrites3-rewrite-rules

RewriteRule only works for home page


I have this RewriteRule which create a permanent redirection from example1.com to example2.com

In the htaccess of example1.com I have these rules:

    #Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^(.*)$ https://www.example2.com/$1 [R=301,L]

The redirection works fine for https://www.example1.com/ (it gets redirected to https://www.example2.com). But it does not work for https://www.example1.com/about-us

I expect https://www.example1.com/about-us to be redirected to https://www.example2.com/about-us


Solution

  • Change your rewrite to this one:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com [NC]
    RewriteRule (.*) https://www.example2.com/$1 [R=301,L]