I am trying to do a redirection from old structured links to the new version in htaccess, but I am having no luck.
And the other answers in Stackoverflow dont help.
So I have this link type of link
www.example.com/listings/cat/shoes/state/nevada
www.example.com/listings/cat/heels/state/arkansas
www.example.com/listings/cat/skirts/state/florida
Which I want to convert to
www.example.com/directory/cat/shoes/region/nevada
www.example.com/directory/cat/heels/region/arkansas
www.example.com/directory/cat/skirts/region/florida
I have tried this but didn't work as expected.
RedirectMatch 301 /listings/cat/(.+)$/state/(.+)$ http://www.example.com/directory/cat/$1/region/$2
Your regex has anchor $ more than once.
You can use this rule:
RedirectMatch 301 ^/listings/(cat/.+)/state/(.+)$ /directory/$1/region/$2
Related
I'm trying to redirect the URLs of my old page to the new.
There the logic of the language has changed.
Old:
http://example.com/cms/de/help-contact/glossar/cookie
New:
http://example.com/cms/de/cookie
I have several languages with same slug, just difference in language slug.
So i want to try to redirect the urls dynamically.
When i do it directly, it works like:
Redirect 301 /cms/de/help-contact/glossar/cookie /cms/de/cookie
I googled and found some posts but nothing that helped me really.
So i already tried:
Redirect 301 /cms/([^/]+)/help-contact/glossar/cookie /cms/$1/cookie
Or:
Redirect 301 /cms/([a-z]{2})/help-contact/glossar/cookie /cms/$1/cookie
But it didn't wokred.
Any idea?
Thanks.
Redirect directive doesnt support regex. What you are looking for is RedirectMatch .
RedirectMatch 301 ^/cms/([^/]+)/help-contant/glossar/(.+)$ /cms/$1/$2/
I am not able to find the error in the following Htaccess Code.
Isn't it just a simple 301 redirection?
Redirect 301 flaechenformeln.html http://www.mathespass.at/formeln/flaechenformeln.php
I have also tried to change the redirect a bit, but it is not working.
But however this works:
Redirect 301 /testversion/klasse2/index.html http://www.mathespass.at/testversion/klasse2/index.php
Isn't it the same?
Hope you can help me!
With best greetings
Redirect directive performs starting string match of the REQUEST_URI with the given pattern and it must start with a /.
Try this rule instead:
Redirect 301 /flaechenformeln.html http://www.mathespass.at/formeln/flaechenformeln.php
I need to redirect my old blog folder to my new blog folder but keep post-titles the name.
/oldblog/post-title to /newblog/post-title
I wrote:
RedirectMatch 301 /oldblog/(.*) /newblog/$1
This works until I bump into a url like /oldblog/events/
I want to exclude /oldblog/events/ from this rule. Thanks.
To exclude the oldblog/events , you can use :
RedirectMatch 301 ^/oldblog/((?!events).*)$ /newblog/$1
Clear your browser's cache before testing this code.
I've a problem about Redirect by htaccess.
It is all the link like this: abc.com/cate/yyyy/mm/yyyy_postname
Redirect to link like this: abc.com/post-yyyymm/postname
I was try this:
RedirectMatch 301 ^cate/([0-9]{4})/([0-9]{2})/([0-9]{4})_(.*)$ post-([0-9]{4})/([0-9]{2})/$1
But it not working.
Please help me, thank you so much.
You have to use back-references on RHS of your rule:
RedirectMatch 301 ^/cate/([0-9]{4})/([0-9]{2})/([0-9]{4})_(.*)$ /post-$1$2/$4
Thank to Anubhava,
Your help is useful.
Although it not redirect to the correct url result.
It redirect to: acb.com/post-yyyy/mm/yyyy_
BUT It help me go deeper to understand the way to use your help.
And I was try to change like this:
RedirectMatch 301 ^/cate/([0-9]{4})/([0-9]{2})/([0-9]{4})_(.*)$ /post-$1$2/$4
Haha, so crazy, that working.
It redirect exactly from link: acb.com/cate/yyyy/mm/yyyy_postname
To link: acb.com/post-yyyymm/postname
Thank again to Anubhava.
on .httaccess, we use like this.
RedirectMatch 301 ^/food/(.*)$ http//:domain.com/food-for-healthy/$1
It works well. but we have a problem with 1 old link. we used to have a multi-site and the name is "food". it was changed to "food-for-healthy". Therefore we have changed like so:
RedirectMatch 301 ^/food/(.*)$ http//:domain.com/food-for-healthy/$1
and as you know, http//:domain.com/food/ and http//:domain.com/food are the same.
The problem is http//:domain.com/food which needs to go to http//:domain.com/food-for-healty/
I have tried several things but my attempts produce a redirect error.
RedirectMatch 301 /food http//:domain.com/food-for-healthy
this gets a redirect error. how can I change it to work properly?
I have tried this..
RedirectMatch 301 ^/food/?(.*)$ http//:domain.com/food-for-healthy/$1
but
it comes with a redirect error and goes to
http:/:domain.com/food-for-healthy/food-for-healthy/food-for-healthy/food-for-healthy/food-for-healthy/food-for-healthy/food-for-healthy/food-for-healthy/...
There's no reason I can see why RedirectMatch is required since you're doing a simple redirect from one place to another and aren't dealing with additional query string values or sub-pages (that you've said).
Redirect permanent /food/ http://domain.com/food-for-healthy/