301 Redirection for any url in my website - .htaccess

I need to create a 301 redirection from myOldSite.com to myNewSite.com
I have this code in the htaccess in myOldSite.com
#Redirect 301 / https://myNewSite.com/myPage/
This works fine to redirect myOldSite.com but it does not work to fire the right redirection for myOldSite.com/services.html:
myOldSite.com is properly redirected to myNewSite.com/myPage
But
myOldSite.com/services is redirected to myNewSite.com/myPage/services.html This is wrong.
As you can see servicesis appended to the end. This is not what I need. I need:
myOldSite.com/services to be redirected to myNewSite.com/myPage
Any url which start with myOldSite.com/ANYTHING_HERE should be redirected to myNewSite.com/myPage

Use RedirectMatch
RedirectMatch 301 / https://myNewSite.com/myPage
This will not append the old URL subpath to the destination URL.

Related

301 Redirect in .htaccess is appending old file path/name to new url

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
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

Capture middle directory and redirect to new url

The URL I'm working with is something like this...
old-website/directory/sub-directory/last-directory
I need to capture just the sub-directory portion and then use that in a URL for a redirect. For example, redirect to new-website/working/sub-directory/page
However, I also need a redirect that works for old-website/directory/sub-directory to redirect to the same new-website/working/sub-directory/page
You can use this RedirectMatch rule in your root .htaccess:
RedirectMatch 302 ^/directory/([^/]+)(?:/.*)?$ http://working/$1/page
Change 302 to 301 once you verify that rule is working fine.

301 redirects in .htaccess forming incorrect redirect

I'm trying to redirect http://brisbaneamazingrace.com.au/details.html to http://www.teambonding.com.au/activities/amazing-race-brisbane which is a different domain. In my .htaccess file I have
Redirect 301 http://brisbaneamazingrace.com.au/details.html http://www.teambonding.com.au/activities/amazing-race-brisbane
But the redirect goes to http://teambonding.com.au/activities/amazing-race-brisbanedetails.html
It keeps adding the details.html to the end of the redirect url. Whats up with that?
You should use RedirectMatch for regex matching:
RedirectMatxh 301 ^/details\.html$ http://www.teambonding.com.au/activities/amazing-race-brisbane
Also test this after clearing your browser cache.

Using .htaccess to redirect to a subfolder

I'm trying to 301 redirect from '/en' or '/en/' to '/en/home' using .htaccess, but any attempt I do results into a redirection loop '/en/home/home/home/home/home/home...'.Shouldn't it be as simple as Redirect 301 /en /en/home?
Redirect based rule keep matching /en in redirected URL as well. You can use RedirectMatch for this with regex support:
RedirectMatch 301 ^/(en)/?$ /$1/home
Also make sure to clear your browser cache when you test this.
You have to use the full URL, example:
redirect 301 /folder_wrong/name.html http://website.com/folder-right/name.html

Magento 301 htacess redirect not working at all

i am writing a 301 redirects via htaccess redirect old traffic to new urls
ex
i have old url
http://www.thebedroom.com.au/catalogue/accessories/product134
i need to redirect this request to
http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
so i wrote a code on magento httpacess like below
Redirect 301 http://www.thebedroom.com.au/catalogue/accessories/product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
no luck
and also tried
Redirect 301 ^accessories/product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
but this not redirectoring and show the same url on browser window.
anyone know what is the issue here
thank you
Try:
Redirect 301 /catalogue/accessories/product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
or
RedirectMatch 301 product134 http://www.thebedroom.com.au/melbourne-demons-bean-bag-cover.html
which will redirect if there's any instance of product134 in the URI.

Resources