سؤال

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