Adding .html onto the end of a URL

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

Read More

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?

Related posts

Leave a Reply

2 comments

  1. 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.

  2. I believe you can just go to Admin → Settings → Permalinks and set the permalinks to custom with a value of:

    /%year%/%monthnum%/%day%/%postname%.html