Results 1 to 3 of 3

Thread: How do I remove file extensions from my URl

  1. #1
    Join Date
    Jun 2008

    How do I remove file extensions from my URl

    Hi everyone,

    So I've been wondering how to hide extension from my URl. Say I have www.mysite.com/about/about-us.html or www.mysite.com/contact.php and I want it to show as www.mysite.com/about/about-us or www.mysite.com/contact how do i do that?

    needless to say I've tried out severally php codes on several forums and none of them really works. So am wondering if there's anybody that can show or offer me a really good working code.

    Thanks in advance

  2. #2
    Join Date
    Oct 2013
    For small sites, 5-10 pages, the easiest thing to do is give each file its own folder and name it index.yyy. For example, www.mysite/about/about-us/index.html. Now your link code can look like <a href="/about/about-us">about us</a>. Apache will serve index.html (or .php, or .htm) by default, but will also serve it with a trailing slash on the URI that shows in the browser. So what the user will see will be www.mysite/about/about-us/ in the address bar.

    Somewhat obviously, once you get beyond just a few files this becomes impractical.

    There may be a .htaccess solution, but I'm a pretty poor regex coder. You might look it up though.

  3. #3
    Join Date
    Jun 2008
    Ok. Was able to get a working code. Thanks Kevin2

    Here's the simple code I used, just in case someone else wanna know:

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

    If you want to remove the .html extension from a html file then you simply have to alter the last line from the code above to match the filename:
    RewriteRule ^([^\.]+)$ $1.html [NC,L]
    Last edited by stini; 12-08-2013 at 07:19 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center