treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Extensionless URLs

  • Hi lovers of CSS-Tricks and Chris!

    I noticed this article based on what i can only assume removes the http://www.css-tricks.com/random".html"
    from the extension of the url.
    http://css-tricks.com/snippets/javascri ... avascript/

    However i wasn't sure ? how would i implement this ?

    Is there a simple way using htaccess and/or Javascript to simple remove the extension from a url?

    I understand you can use the mod_rewrite expression but everytime i try it out i fail!

    Maybe chris you could write a very brief tutorial post ?

    Much lovex
    Mat
  • Actually, that is done by Wordpress.

    If you want to do it manually, you just need to create folders, and put the page in it as index.php.

    Ex:
    domain com/folder-name/index.php

    Then you can just accesse page by typing in:
    domain com/folder-name/

    Enjoy,
  • Yea this method however means i end up with a massive amount of folders in the ftp lol.

    Chris needs to do beginners friendly htaccess tutorial :P
  • Haha. Yes, that is true.

    Another option is to use database driven content and create one file that will decipher which page the visitor wants. Here's the htaccess that Wordpress uses:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress


    This rewrite checks (every time an address is typed into the browser) to see if a file or directory exists already, and if it doesn't it loads the index.php file (which then figures out what page to display based on the URI).
  • Cheers!

    Gunna have a play with it this weekend!