Redirect all pages to a new domain htaccess

57 views Asked by At

I want to redirect my entire website to a new unique address/domain without respecting the relation between filenames.

I don't want olddomain.com/foo.html to be redirected to newdomain.com/foo.html.

I want this result with a htaccess file:

olddomain.com/foo.html => newdomain.com
olddomain.com/foo/bar.html => newdomain.com
olddomain.com/a/b/c/moo.html => newdomain.com

The Redirect 301 function of htaccess does exactly what I don't want.

How I can proceed?

Answer to the RavinderSingh13's comment:

This is what I tried so far:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]

And :

Redirect 301 / https://www.newdomain.com/

And also :

RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.comfr$
RewriteRule ^/?$ "https\:\/\/www\.newdomain\.com/" [R=301,L]
1

There are 1 answers

1
dapgo5 On

Found the answer by reviewing my question:

I just had to remove the $1 at the end as it's a regular expression, it contains the value of the reference script name.

So the working solution for me is:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ https://www.newdomain.com/ [R=301,L]