views:

63

answers:

2

I'm currently using Wordpress as a blogging platform but I want to change to use Jekyll to generate the static pages. On Wordpress my URLs use the following format:

/year/month/day/title

but I want to redirect that to

/year/month/day/title.html

and I can't figure out how to do that using mod_rewrite.

Anyone got any ideas?

+1  A: 
RewriteEngine On
# Only if the URI is not a normal file
RewriteCond %{REQUEST_FILENAME} !-s 
# ... or a symbolic link
RewriteCond %{REQUEST_FILENAME} !-l 
# ... rewrite everything that ends on .html to the stripped down URL
RewriteRule (.+)\.html$ $1 [L]
# Alternatively, if you want to be more specific about the scheme, you can use this
# RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^/]+)\.html$ $1/$2/$3/$4 [L}

The above should give you some pointers on how to properly rewrite the URL to the scheme you desire. This example transparently rewrites everything that ends on .html (except actual files) to the same URL without the .html appended to it.

Aron Rotteveel
If I wanted it to do an actual redirect (probably 301 as well) would I do "RewriteRule (.+)\.html$ $1 [L,R,301]"(without the quotes, obv)?
Piers
Almost correct: you should use [L,R=301]
Aron Rotteveel
Sorry, I misread what you'd put in the Rewrite Rule. It should be taking the current URL and putting .html on the end.Something like the following: RewriteRule (.+)$ $1.html [R=301,L]
Piers
A: 
adam
Not using Wordpress anymore (see OP) and I don't want to lose any google rankings.
Piers
Ahh, I thought you meant you wanted to use Wordpress for posts but bring urls in line with Jekyll (for pages).
adam
I was thinking of that, but then if anyone tried to go to any current pages they'd get a 404. I'm tring to avoid that.
Piers
You might want to test that - WP does some extra stuff. For example, if you have a full permalink structure but try going to /postname, WP will redirect you through.
adam
That's all very well for now, but I'm definately going to be going down the jekyll route so I'm going to want to use mod_rewrite
Piers