I just moved blogging platforms from a custom-made one into WordPress and it looks like a couple of the permalink structures need a 301 redirect. How is this done using regular expressions in regex?
Old: www.domain.com/blog/tag/tag-name.html
New: www.domain.com/blog/tag/tag-name/
Old: www.domain.com/blog/2016/01/01/post-name-here.html
New: www.domain.com/blog/2016/01/01/post-name-here/
While I can do this in the existing .htaccess file, I think this would be impractical as I have a bunch of existing blog posts and categories/tags.
Redirect /blog/2016/01/01/post-name-here.html http://www.domain.com/blog/2016/01/01/post-name-here/
You can use RedirectMatch :
RedirectMatch 301 ^/blog/(tag/)?(.+)\.html$ http://www.example.com/$1$2
This will redirect :
http://www.example.com/blog/tag/foo.html
to
http://www.example.com/blog/tag/foo
or
http://www.example.com/blog/foo.html
to
http://www.example.com/blog/foo
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 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
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.
Hey guys I need the htaccess code to do the following after moving domains.
From:
http://www.techau.tv/blog/review-d-link-2890al-wireless-modem-router/
To:
http://techau.com.au/review-d-link-2890al-wireless-modem-router/
So in the change of domain, I dropped the www and the /blog.
Try adding this to your .htaccess file on http://www.techau.tv :
## 301 Redirect Entire Directory
RedirectMatch 301 http://www.techau.tv/blog/(.*) http://techau.com.au/$1
RedirectMatch 301 http://techau.tv/blog/(.*) http://techau.com.au/$1
Seems to use a regex to do it.
I generated it with this tool by the way: http://www.htaccessredirect.com/
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/