Ad

Redirect Old Domain To New Domain's Homepage

- 1 answer

I want to redirect everything on old domain (but not the homepage because there is still content) to new domain's homepage.

Important: But I don't want to redirect the old homepage. Just the other subfolders like domain.com/*

How to do this? I think this code won't work.

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

Answer

You may use this rule in site root .htaccess:

RewriteEngine On

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

No spaces anywhere in your rule or condition. Also a dot in RewriteRule makes sure to match anything but landing page.

Ad
source: stackoverflow.com
Ad