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/
Related
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
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.
So I'm trying to rewrite the following example. Took a look around but couldn't find the correct post that matched this scenario.
Here is a list of layout for old pages:
www.url.com/directory
www.url.com/directory/page1.html
www.url.com/directory/page2.php
I'm trying to rewrite the following way through htaccess:
Redirect 301 /directory /newdirectory
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
However, the first rewrite rule is interfering with old subpages in that path. So for example, using the above rewrite rules, going to:
www.url.com/directory/page1.html
Points the user to:
www.url.com/newdirectory/page1.html
When it should be pointing user to the slug without the original filename extension:
www.url.com/newdirectory/page1
The only way around this that I've been able to manage is to leave out the www.url.com/newdirectory/page1.html rule entirely. But there are a bunch of links pointing to that base path, so I'd like to redirect that.
Any help would be greatly appreciated. Thanks in advance for the time and help.
url-rewriting redirect rewrite-rules
You need to place the rule for the base directory after the ones for the subpages :
Redirect 301 /directory/page1.html /newdirectory/page1
Redirect 301 /directory/page2.php /newdirectory/page2
Redirect 301 /directory /newdirectory
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/