redirect same sub by slash in htaccess - .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

Related

Problem with path 301 redirects in 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/

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.

.htaccess redirects not working

We've setup a new website for www.immo-turkuaz.be on the domain www.turkuaz.be
In order to get through all the SEO value to the new domain, we've uploaded this .htaccess on www.immo-turkuaz.be
Redirect 301 / http://www.turkuaz.be
Redirect 301 /nl/tekoop.html http://www.turkuaz.be/nl/aanbod
Redirect 301 /nl/in-een-notendop.html http://www.turkuaz.be/nl/info/over-turkuaz/wie-zijn-we
Redirect 301 /nl/vastgoedinfo.html http://www.turkuaz.be/nl/info/infosessies
Redirect 301 /nl/vragen.html http://www.turkuaz.be/nl/info/faq
Redirect 301 /nl/index.html http://www.turkuaz.be/
Redirect 301 /nl/getuigenissen.html http://www.turkuaz.be/getuigenissen
Redirect 301 /nl/over-turkije.html http://www.turkuaz.be/nl/info/over-turkije
Redirect 301 /nl/regio.html http://www.turkuaz.be/nl/aanbod
Redirect 301 /nl/contact.html http://www.turkuaz.be/nl/contact
Redirect 301 /nl/projectbegeleiding.html http://www.turkuaz.be/nl/info/projectbegeleiding
Redirect 301 /nl/links.html http://www.turkuaz.be/nl/info/links
Redirect 301 /nl/detail/91/k2-deluxe-residence.html http://www.turkuaz.be/nl/aanbod/side/item/17-k2-deluxe-residence
Redirect 301 /nl/bezichtiging.html http://www.turkuaz.be/nl
Redirect 301 /nl/activiteiten.html http://www.turkuaz.be/nl/info/over-turkuaz/hoe-werken-we
Redirect 301 /nl/detail/86/zen.html http://www.turkuaz.be/nl/aanbod/side/item/24-naam-van-de-residentie
Redirect 301 /nl/detail/9/q-spa-resort.html http://www.turkuaz.be/nl/aanbod/side/item/23-q-spa-resort
Redirect 301 /nl/detail/34/city-highlights-ii.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/22-city-highlights
Redirect 301 /nl/detail/14/the-hill.html http://www.turkuaz.be/nl/aanbod/side/item/21-the-hill-side
Redirect 301 /nl/detail/78/felicia-residence.html http://www.turkuaz.be/nl/aanbod/side/item/20-felicia-residence
Redirect 301 /nl/detail/35/orka-valley-spa---sport-complex.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/19-orka-valley
Redirect 301 /nl/detail/22/the-valley.html http://www.turkuaz.be/nl/aanbod/side/item/18-the-valley
Redirect 301 /nl/detail/38/golden-heights-ii.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/1-new-golden-heights
Redirect 301 /nl/detail/57/klaros-residence.html http://www.turkuaz.be/nl/
Redirect 301 /nl/detail/18/q-garden.html http://www.turkuaz.be/nl/aanbod/side/item/16-q-garden
Redirect 301 /nl/detail/56/sarigerme-heights.html http://www.turkuaz.be/nl/
Redirect 301 /nl/detail/17/majestica.html http://www.turkuaz.be/nl/aanbod/side/item/15-majestica
Redirect 301 /nl/detail/59/lakeshore-golf.html http://www.turkuaz.be/nl/aanbod/bodrum/item/14-lakeshore-golf
Redirect 301 /nl/detail/10/babylon.html http://www.turkuaz.be/nl/aanbod/side/item/13-babylon
Redirect 301 /nl/detail/15/agora.html http://www.turkuaz.be/nl/aanbod/side/item/12-agora-f11
Redirect 301 /nl/detail/16/citrus-garden.html http://www.turkuaz.be/nl/aanbod/side/item/11-citrus-garden
Redirect 301 /nl/detail/84/spring-3-appartement-a3.html http://www.turkuaz.be/nl/aanbod/side/item/9-spring-3-a3
Redirect 301 /nl/detail/82/royal-hills.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/8-royal-hills
Redirect 301 /nl/detail/21/mandarin-garden.html http://www.turkuaz.be/nl/aanbod/side/item/7-mandarin-garden
Redirect 301 /nl/detail/23/tropicana.html http://www.turkuaz.be/nl/aanbod/side/item/6-tropicana
Redirect 301 /nl/detail/33/orka-park.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/5-orka-park
Redirect 301 /nl/detail/25/sunset-residence.html http://www.turkuaz.be/nl
Redirect 301 /nl/detail/27/olive-grove.html http://www.turkuaz.be/nl/aanbod/side/item/4-olive-grove
Redirect 301 /nl/detail/29/okeanus.html http://www.turkuaz.be/nl/aanbod/side/item/3-okeanus
Redirect 301 /nl/detail/32/custom-build-villa.html http://www.turkuaz.be/nl/aanbod/side/item/2-custom-build-villa
Redirect 301 /nl/detail/42/uzumlu-mountain-villa.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/41-oasis-uzumlu-villa
Redirect 301 /nl/detail/40/crown-villa.html http://www.turkuaz.be/nl/
Redirect 301 /nl/detail/41/orka-gardens.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/40-orka-gardens
Redirect 301 /nl/detail/43/oasis-uzumlu-villa.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/41-oasis-uzumlu-villa
Redirect 301 /nl/detail/52/centre-point-studio-s-en-appartementen.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/42-centre-point
Redirect 301 /nl/detail/85/duplex-city-highlight-i.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/43-duplex-city-highlight
Redirect 301 /nl/detail/53/olivia-apartments.html http://www.turkuaz.be/nl
Redirect 301 /nl/detail/54/olive-gold-villas.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/44-olive-gold-villas
Redirect 301 /nl/detail/55/orka-diamond-collection.html http://www.turkuaz.be/nl/aanbod/dalaman-fethiye/item/54-diamond-collection
Now, this doesn't work as it should....
e.g.
www.immo-turkuaz.be/nl/tekoop.html redirects to www.turkuaz.be/nl/tekoop.html
While it should redirect to www.turkuaz.be/nl/aanbod (as you can see in the .htaccess content.
Only the homepage redirects well.
What am I doing wrong?
You might put the Homepage-Redirect to the most bottom of the list. Otherwise it will always redirect "/" and all containing files/folders first.
That is due to your very first rule:
Redirect 301 / http://www.turkuaz.be
Which is catching all the URLs and redirecting same to new host.
Move that line to the bottom of your .htaccess and retest 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?

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

Resources