Using .htaccess
I am trying to setup a simple 301 redirect which redirects both exampleA.com
and www.exampleA.com
(the old domain) to exampleB.com
(the new domain). However, accessing www.exampleA.com
results in a 403 Forbidden status.
Both exampleA.com
and exampleB.com
point to the same hosting account.
So, in summary:
http://exampleA.com
redirect tohttp://exampleB.com
- OKhttp://www.exampleA.com
redirect tohttp://exampleB.com
- 403 Forbidden
.htaccess code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^exampleA\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.exampleA\.com$
RewriteRule ^(.*)$ http://exampleB.com/$1 [L,R=301]]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(html|php|htm)\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)\.(html|php|htm)$ http://exampleB.com/$1 [L,R=301]
</IfModule>
Note: I am making these changes in the htaccess file of the current new domain website.
- How do I need to change the syntax to redirect both non-www and www to the new domain without getting a 403 response?
- If I make changes to the htaccess file are these reflected instantly or do they take time?
I am making these changes in the htaccess file of the current new domain website.
Err? You can't do that unless they share the same file space, which isn't a good idea. You should use two .htaccess files, one for the old domain and where that is hosted, i.e/var/www/public_html/exampleA.com
and then another in/var/www/public_html/exampleB.com
. Your exampleA (old domain should redirect everything to the new domain, no need to setup rules in the .htaccess for the new domain.exampleA.com
toexampleB.com
?