Awesome .htaccess for having pretty urls with static html files

Discussion in 'General Programming Chat' started by paincake, Aug 9, 2012.

  1. paincake

    paincake Power Member

    Joined:
    Aug 18, 2010
    Messages:
    716
    Likes Received:
    3,100
    Home Page:
    Save this as .htaccess and put it in your website root folder:
    Code:
    RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)/$ $1.html [L]
    These rules will automatically redirect urls to corresponding html files.

    For example, if your visitors go to:

    www.yoursite.com/page1-test/

    they will see the contents of page1-test.html