Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect all pages to new domain

I want to redirect all the pages of my website to a new domain with a redirect. I've managed to get it working on domain level but not on the subpages.

So olddomain.com redirects to newdomain.com but olddomain.com/contact doesn't redirect to newdomain.com. It still shows the old domain.

I've used multiple rewrites rules but none of them seem to works. Any help is much appreciated.

This is the code that I'm using right now in my .htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


RewriteCond %{HTTP_HOST} ^racentegenkanker\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.racentegenkanker\.com$
RewriteRule ^(.*)$ "http\:\/\/againstcancer\.nl\/$1" [R=301,L]
like image 616
NielsPilon Avatar asked Dec 26 '22 07:12

NielsPilon


1 Answers

For a full website redirection, you can use this (entire) .htaccess :

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]

EDIT

For two domains running side by side, with one redirecting the other :

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} racentegenkanker\.com$ 
RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
like image 186
zessx Avatar answered Jan 03 '23 10:01

zessx