views:

72

answers:

1

Hi guys,

I'm trying to get a set of 301 redirects working for a client site, and I'm getting a bit stuck.

I have about 17 different directories that have .html content fileswhich I am moving across to Wordpress. What I am trying to do is create a simple, single .htaccess file with redirects in that will allow me to redirect all the .html files within a directory to wordpress URLs without an extension:

Manual redirect example:

redirect 301 /blog/2009/04/post1.html /blog/2009/04/post1/
redirect 301 /blog/2009/04/post2.html /blog/2009/04/post2/

Trying to create a rule like:

RewriteRule ^/blog/2009/04/(.*?).html$ /blog/2009/04/$1/ [R=301,NC,L]

Where the $1 is the filename (minus the .html) suffixed with a /

I can't determine whether the ^/blog/2009/04/(.*?).html$ means it will only redirect for this particular directory, and will redirect to the right location.

I would obviously want to duplicate this ReWriteRule for all my designated content directories...

Can anyone point me in the right direction?

Thanks,

Lee

+1  A: 

Yes, your rule will only redirect for the 2009/04 directory. I think you want:

RewriteRule ^/blog/([0-9]+)/([0-9]+)/(.*?).html$ /blog/$1/$2/$3/ [R=301,NC,L]

This will now also redirect /blog/2008/12/post.html to /blog/2008/12/post/ and so on. Although since you have almost exactly the same format, maybe this will be easier?

RewriteRule ^/blog/(.*?).html$ /blog/$1/ [R=301,NC,L]
DisgruntledGoat
Will I be able to use something like:RewriteRule ^/services/(.*?).html$ /services/$1/ [R=301,NC,L]For non-blog directories?
Geniuswood
Yes, if the bit in `(.*?)` will be the same as where you put the `$1`.
DisgruntledGoat