0
votes

I have a blog (wordpress version 3.01) which has custom based permalinks in the following format: /%category%/%postname%/. For example, blog.com/category/post-name/.

I need to change permalinks to "Day and name" /%year%/%monthnum%/%day%/%postname%/ (my Theme requires that to work properly).

What do I need to write in my .htaccess file to make the old permalinks 301 to redirect to the new ones?

My site is 9 months old and has about 500 articles.


Example

/%category%/%postname%/ to /%postname%/

RedirectMatch 301 ^/([^/]+)/([^/]+)/$ http://www.mydomain.com/$2

My case is to get this

/%category%/%postname%/ to /%year%/%monthnum%/%day%/%postname%/

RedirectMatch 301 ???????????

1

1 Answers

0
votes

You cant do this with an .htaccess file as the rewrite feature (RewriteMap) which could do this doesn't work in a .htaccess context. However, since you've got a closed list and therefore a fixed list of categories, it is simple to map these to a common redirector script:

RewriteEngine On
RewriteBase   /

RewriteRule ^(cat1|cat2|cat3|cat4)/.*?/$ redirector.php?cat=$1&post=$2 [L,QSA]

(extending the cat list to be a complete list of categories). Then redirector.php is a standard redirector pattern. You simply query your Wordpress D/B to determine the YMD for the post to issue a

$server  = $_SERVER['HTTP_HOST'];
header( "Location: HTTP://$server/$year/$month/$day/$postName/", true, 302 );

before exiting.