Htaccess redirects with domain masking not working when querying the root directory

You need help with redirection + masking a domain using .htaccess. It partially works. It works for subpages and subdirectories, but not for the domain itself.

I have two domains: redir1 and redir2. The goal is to redirect using .htaccess and mask as follows:

http://redir2 —> http://redir1
http://redir2/sub.php —> http://redir1/sub.php
http://redir2/index.php —> http://redir1/index.php

And the URL displayed to the visitor should remain what they entered:

http://redir2
http://redir2/sub.php
http://redir2/index.php

But if they are logged in http://redir1, they should see http://redir1in the url.

each domain has the following two files: index.php sub.php

Here is the code in .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?redir2$ [NC]
RewriteRule ^ http://redir1%{REQUEST_URI} [L,NE,P]

It works very well for all requests that have something after the domain (subpages and subdirectories). For instance:

http://redir2/sub.php
http://redir2/index.php

But if I type only http://redir2/, I get a "Not Found" error:

The requested URL /index.html was not found on this server.

, index.html, index.php index.html?

0
1

DirectoryIndex index.php?

0

All Articles