I am trying to do a simple 301 redirect for the following URLs:

From:

http://example.com/blog/category/*
http://example.com/blog/tag/*

To:

http://example.com/category/*
http://example.com/tag/*

Where the * character represents any given category or tag that could possibly be requested.

So I need to have a wildcard in place so that whenever any category or tag is requested, it redirects to the URL without the blog folder.

Is there any way to achieve this with a 301 redirect in my .htaccess file?

有帮助吗?

解决方案

RedirectMatch would be better for its regex capabilities. Use this rule in your DocumentRoot/.htaccess:

RedirectMatch 301 ^/blog/(category|tag)/(.*)$ /$1/$2
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top