Using .htaccess to redirect to a subfolder - .htaccess

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

Related

301 Redirection for any url in my website

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.

301 Redirect just first Subfolder

I have a 301 Redirect from one page to another
REDIRECT 301 /cloud-computing /it-infrastructure/cloud-computing
Now when i use this redirect also the subpages of cloud-computing are affected by this 301 redirect, but they have to be redirected somewhere else. How can i just redirect the folder and not the subpages?
You should be using RedirectMatch for precise matching using regex:
RedirectMatch 301 ^/cloud-computing/?$ /it-infrastructure/cloud-computing
Clear your browser cache before testing the change.

When I use 301 redirect, I get the wrong url address

My redirect is as follows:
Redirect 301 / http://testsite.com/en/
I get the following address: testsite.com/en/en/en/en/en/en/en/en
I worked in a .htaccess file. Where is my mistake?
You should use RedirectMatch to target precise URL using regex:
RedirectMatch 301 ^/$ http://testsite.com/en/
Make sure to test this after clearing your browser cache.

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.

301 redirect not working with sub page

I've setup some 301 redirects in my .htaccess file.
Redirect 301 /accounts http://www.domain.com/priority-accounts/
Redirect 301 /accounts/benefits http://www.domain.com/priority-accounts/
The first one redirect to /priority-accounts/ as expected but the second redirects to /priority-accounts/benefits.
Why is this? I just want the second redirect to go to /priority-accounts/
Thanks
Ok it works if I use
RedirectMatch 301 ^/accounts/benefits$ http://www.domain.com/priority-accounts/
But only without the trailing '/'
Do I have to write another one with the trailing '/'? like this?
RedirectMatch 301 ^/accounts/benefits/$ http://www.domain.com/priority-accounts/
Surely there's a better way?

Resources