1

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]
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dapgo5
  • 29
  • 4

1 Answers1

1

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]
dapgo5
  • 29
  • 4
  • 1
    `^(.*)$` - there's no need to capture the URL-path if this is not being used. A mod_alias `RedirectMatch 301 ^ https://www.newdomain.com/` is arguably simpler. – MrWhite Feb 13 '21 at 21:35