2

I have two URLs: old-site.com and new-site.com. My root folder on the old-site.com has NO FILES in it but only the .htaccess file. I don’t want to use the old domain anymore. However, I do want to pass the link juice to the new domain. Therefore, I created 301 Redirects in the .htaccess file and put it in the root folder on the old-site.com.

Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?

My entire .htaccess looks like this (I skipped a few links to shorten it):

#Begin 301 Redirects
Redirect 301 / https://www.new-site.com/
Redirect 301 /contactus https://www.new-site/contact-us/
Redirect 301 /rentals https://www.new-site/lodging/
Redirect 301 /lift.html https://www.new-site/our-rentals/boat/
Redirect 301 /rentals.html https://www.new-site/our-rentals/
Redirect 301 /map.html https://www.new-site/contact-us/
Redirect 301 /giftshop https://www.new-site/store/gift-shop/
#End 301 Redirects

I don’t have any Rewrites. The above is my entire code.

The following redirect works fine:

Redirect 301 / https://www.new-site.com/

However, any other redirect creates the following absolute path on the new-site.com with a 404 error:

If I redirect:

Redirect 301 /contactus https://www.new-site/contact-us/

It goes to:


https://www.new-site.com/old-site.com/contactus

or

If I redirect:

Redirect 301 /lift.html https://www.new-site/lift/

It goes to:


https://www.new-site.com/old-site.com/lift.html

Why would the Redirect 301 append the “old-site.com/…” to the new-site.com?

Thank you,

Derek

1 Answers1

2

Your rules will not do what you need correct because of this line Redirect 301 / https://www.new-site.com/ which will match any request first and if you put it in the last it will also match any request so , if you want it to match only root use RedirectMatch to be able to use regex like this :

RedirectMatch 301 /?$ https://www.new-site.com/

By this the rest of rules will work as expected .

Note: clear browser cache the test

Mohammed Elhag
  • 4,272
  • 1
  • 10
  • 18
  • "you put it in the last it will also match any request" - But reversing the order of the directives would ordinarily be the solution here, since they no longer want to use the "old domain". However, this does not address why `old-site.com` is appearing in the URL-path of the target URL. But the regex `/?$` doesn't only redirect the homepage, it redirects _everything_! (And redirecting everything to the homepage on the new site - so you certainly would need to have changed the order of the directives anyway!) The regex should be `^/$` to redirect the homepage only. – MrWhite Apr 03 '23 at 09:52