Reputation: 788
I have a bunch of domains that all go to the same site and need to be able to redirect domainalias.com/folder/name to website.com/folder/name.
I currently have the following htaccess which works as far as redirecting the root domain, but as soon as I go into a sub-directory or sub-page, it won't redirect:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
# Redirect all domains to website.co.uk
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^website.co.uk$ [NC]
RewriteRule ^(.*)$ http://website.co.uk/$1 [L,R=301]
</IfModule>
So to confirm, I want people to be redirected from http://anydomainalias.co.uk/any/sub/folder to http://website.co.uk/any/sub/folder. As it's a WordPress site, I need this to work dynamically. I have 50-odd subdomains so want to avoid having a rule for each one as well (hence the !^website.co.uk rule).
Thanks.
Upvotes: 2
Views: 1370
Reputation: 785256
Have redirect rule before default WP routing rule:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect all domains to website.co.uk
RewriteCond %{HTTP_HOST} !^website\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://website.co.uk/$1 [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
Make sure to test it after clearing your browser cache.
Upvotes: 1