Problem with path 301 redirects in htaccess - .htaccess

We're trying to redirect a bunch of category URLs like this:
Redirect 301 /table/ https://www.example.com/abc/
Redirect 301 /table/accessoires/ https://www.example.com/def/
Redirect 301 /table/accessoires/tablecloth/ https://www.example.com/ghj/
The first redirect works correctly. But why do the other 2 don't work?

Order matters. The more specific rules should be first.
Redirect 301 /table/accessoires/tablecloth/ https://www.example.com/ghj/
Redirect 301 /table/accessoires/ https://www.example.com/def
Redirect 301 /table/ https://www.example.com/abc/

Related

.htaccess Redirect 301 Strange behaviour

I have a new Website that consists of 1 Domain and 2 Subdomains:
Domain:
www.bluepuma.at
Subdomain:
werbeagentur.bluepuma.at
werbetechnik.bluepuma.at
The old website only had 1 Domain: www.bluepuma.at
Now I wrote a bunch of Redirects to redirect the old directorys from the old website to the new one:
I wrote them in the .htaccess which is in the root domain directory in www.bluepuma.at:
Redirect 301 /werbeagentur-bluepuma/wer-ist-bluepuma/ https://werbeagentur.bluepuma.at/
Redirect 301 /werbeagentur-bluepuma/jobs/ https://werbetechnik.bluepuma.at/werbetechnik/jobs-lienz
Redirect 301 /agentur/online-marketing/suchmaschinenoptimierung/ https://werbeagentur.bluepuma.at/online-werbung/online-marketing
Redirect 301 /agentur/online-marketing/suchmaschinenmarketing/ https://werbeagentur.bluepuma.at/online-werbung/online-marketing
Redirect 301 /agentur/online-marketing/social-media-marketing/ https://werbeagentur.bluepuma.at/online-werbung/social-media-marketing
Redirect 301 /agentur/online-marketing/newsletter-marketing/ https://werbeagentur.bluepuma.at/online-werbung/online-marketing
Redirect 301 /agentur/online-marketing/videomarketing/ https://werbeagentur.bluepuma.at/online-werbung/produktfotografie
Redirect 301 /agentur/online-marketing/analyse-controlling-reporting/ https://werbeagentur.bluepuma.at/online-werbung/online-marketing
Redirect 301 /agentur/online-marketing/marketing-konzepte-planung/ https://werbeagentur.bluepuma.at/online-werbung/online-marketing
Redirect 301 /agentur/online-marketing/ https://werbeagentur.bluepuma.at/online-werbung/online-
Now I have the problem, that the Redirect also work on the Subdomain:
Example:
If I open https://werbeagentur.bluepuma.at/werbeagentur-bluepuma/wer-ist-bluepuma/
I get redirected to https://werbeagentur.bluepuma.at/ according to this redirect statement:
Redirect 301 /werbeagentur-bluepuma/wer-ist-bluepuma/ https://werbeagentur.bluepuma.at/
But this should not be possible.
The Redirects should only affect the main domain. For example:
www.bluepuma.at/werbeagentur-bluepuma/wer-ist-bluepuma/ should get redirected to https://werbeagentur.bluepuma.at/
Do you have any ideas why this could be?
Another strange behaviour: If I open
www.bluepuma.at/agentur/online-marketing/suchmaschinenoptimierung/
I get to the page
https://werbeagentur.bluepuma.at/online-werbung/online-marketingsuchmaschinenoptimierung/
I have no idea what causes this error.
Thanks for your answer and your time!

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

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.

Order of 301 Redirects?

I am curious if someone could educate me to better understand why the following does not work based on the order.
When I have the redirect for /contact first the location pages fail to redirect properly.
Redirect 301 /contact http://www.example.com/contact-us
Redirect 301 /index.php/contact/location1 http://www.example.com/contact-us/location1
Redirect 301 /index.php/contact/location2 http://www.example.com/contact-us/location1
When I have it after the locations, they work normally. Why is this?
Redirect 301 /index.php/contact/location1 http://www.example.com/contact-us/location1
Redirect 301 /index.php/contact/location2 http://www.example.com/contact-us/location1
Redirect 301 /contact http://www.example.com/contact-us
It is because other 2 URLs also have /contact in them.
It is always better to use RedirectMatchdirective that with capability to use regex so that you can match exactly what you need.
Using RedirectMatchdirective following will also work:
RedirectMatch 301 ^/contact/?$ http://www.example.com/contact-us
RedirectMatch 301 ^/index\.php/contact/location1/?$ http://www.example.com/contact-us/location1
RedirectMatch 301 ^/index\.php/contact/location2/?$ http://www.example.com/contact-us/location1

redirect same sub by slash in htaccess

How to redirect as:
Redirect 301 /ruler/ http://www.sample.com/ruler/
Redirect 301 /ruler/red/review http://www.sample.com/product_review/flexible-ruler/
Redirect 301 /ruler/read/ http://www.sample.com/read/soft-ruler/
with above code, it not work correct. with
Redirect 301 /ruler/red/review will to http://www.sample.com/ruler/
Thanks about helps!
You need to put Redirect 301 /ruler/red/review line before Redirect 301 /ruler/, read more about Order of Processing

Resources