I recently created a new site on a different domain. I need to redirect the index.html
of the old domain to the index of the new domain.
Usually this would not be a problem, but the old domain is the root domain of the server, the new one is an add on. So the following line would cause a redirect loop because it redirects a.com/index.html
and b.com/index.html
to b.com/index.html
.
Redirect 301 /index.html http://b.com/
Is there a way of doing something like this?
Redirect 301 http://a.com/index.html http://b.com/
TL;DR How can I redirect index.html
on one domain to another domain without it cascading and causing a loop because the other domain is a add on domain (i.e. in the same folder therefor under the law of the same .htaccess
).
You can try mod_rewrite for more flexibility with the code like this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for HTTP
RewriteCond %{HTTP_HOST} ^a\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(index\.html)$ http://b.com/$1 [R=301,L,NC]
# for HTTPS
RewriteCond %{HTTP_HOST} ^a\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(index\.html)$ https://b.com/$1 [R=301,L,NC]