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

remove html and/or PHP extensions in URL

  • Does anyone know how to remove the .html or .php extensions from appearing in the URL? My example would be like (before) http://www.testing/remove.html to (after) http://www.testing/remove
    I searched Chris's site and this forum, I could not find an answer, unless I overlooked it. I did not know if anyone out here was familiar with this or not? I researched the web, I know this requires coding in the .htaccess.txt file. However, some of the example codes I tried never worked for some reason.

    One example code:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME}!-d
    RewriteCond %{REQUEST_FILENAME}!-f
    RewriteRule ^([^.]+)\.php$ $1 [L]

    Two of my PHP books, do not even mention this?

    Any help would be appreciated!

    Sincerely,
    Todd
  • have you tried looking up for pretty URLs?

    I have had a very quick look for you, but it only deals with the file name e.g. test/test.php = test/ not test/test

    but to be honest it might be confusing to do it your way (for the reader I mean)
  • I just searched "htaccess remove file extension" and this was the first thing that popped up http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
  • Just to make sure the obvious is covered here....

    You could create a directory called "remove" in your root directory and put an index.html file inside of that and you'd have /remove/ working no problem.
  • Chris, you know I did'nt even think about creating a directory. I will try that that. Thanks for the replies everyone!