Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Many times I see that URL extensions are hidden (e.g. .html, .php), but not all websites do this.

Why do webmasters hide the extension? Is it for security, for the URL to look cleaner, or for some other purpose?

share|improve this question
up vote 29 down vote accepted

There are several reasons to remove extensions from URLs:

  • To make the URLs look cleaner
  • To make URLs easier to type
  • To make URLs easier to remember
  • To make URLs more SEO keyword friendly
  • To be able to change technologies -- if you ever want to move your site from one technology to the other, its easiest to do so without users even knowing if there are no extensions on the URLs

Keep in mind that many sites are generated by a content management system (CMS) that would make URLs look like this: /index.php?page=this-is-the-widget-page. That is particularly ugly and has far more cruft than just an extension. Rewriting to remove index.php?page= makes it much better.

Extensions are not needed on the web because servers send the type of document as a header. Web pages are served as text/html, images as image/png or image/jpeg. This lets browsers know how to render the content without using an extension to figure out that the URL contains text, HTML, PDF or image (for more information see the Wikipedia article Internet media type).

Some webmasters choose to use an extension on their URLs that matches this content type. So any text/html document would have a .html extension and any image/png document would have a .png extension. That can help when the URLs are saved to the file system where the meta data about their content type is lost. In most file systems, the program that opens the file is chosen by the extension. So even if a page is served by PHP, some webmasters remove the .php extension, and some replace it by .html.

There is also the question as to whether URLs might be better ending in trailing slash (/) when they have no extension which has a lot of discussion on Stack Overflow.

share|improve this answer
In some frameworks (e.g. MVC) the URL doesn't identify a file, so there is no extension to hide. – Henrik Ripa May 10 '13 at 8:31

All web servers have one or more "default files". It's the file that will be displayed whenever a visitor goes to a URL that ends in a slash /, i.e. a folder.

If the default file name on your web server is index.php and a visitor goes to www.example.com/pagename/, they are actually accessing www.example.com/pagename/index.php.

If there is no trailing /, the web server is probably just re-writing the URL to remove it, since it's not necessary. This site, in fact, does that.

share|improve this answer
I'm not sure the question was "how" but rather "why". Patrik your answer is absolutely correct regarding the how. Stephen however, answered the "why" – Brandt Solovij May 9 '13 at 20:02

This is the type of “cool” URI scheme that I aim for on my own personal website.

Personally, the reason that I started to do so (and probably many more web designer/developers too!) was after reading the article “Cool URIs don't change” – this document was written by the World Wide Web's founding father, Tim Berners-Lee.

In Tim Berners-Lee's famous article, he basically states the same reasons that Stephen Ostermiller has in his excellent answer to this question.

To give a more specific answer to your main question, “Why extensions are hidden in URLs?” Well, I would say that the main reasons for me are:

1. To future-proof the URI:

For example, it might have sounded like a good idea at the time to use a URI like: http://www.example.com/page.pl where the .pl being the file exetension for a Perl script. However, thesedays, most web developers use ASP.NET or PHP for backend-scripting, so eve though today, http://www.example.com/page.php sounds like a better idea, eventually PHP and ASP/ASP.net will become old-fashioned. So a better idea is to just remove the extension altogether.

2. Readability and Memorability:

It is much easier for a “cool” URI to be passed to people verbally, on paper (e.g. adverts, business cards etc.), not to mention easier to remember.

3. “Hackability” *

Although I'd say that the vast majority of users these days probably go through a search engine for everything – I've even seen people who would go to the address bar and type www.google.com, and then use Google to literally type in www.ebay.com! But, I think that if I have a website based on multimedia, the URI http://www.example.com/video hints that the music section can be found under the URI http://www.example.com/audio, and so on. (I still use the address bar to go to websites – I'm fairly “old-school” about that sort of thing!)

*(Oh! “Hackability” – does that word even exist?! Well, it does now!) :-)

4. **Aesthetics: To make them look prettier! (Blame my OCD!)

However, I have noticed by reading through various SEO-related websites, that a lot of webmasers actually append a file extensions to dynamic URIs, e.g.:

The actual URI may be: http://www.example.com/article

However, the webmaster will perform a rewrite to make the URI “look” static, such as: http://www.example.com/article.html

The logic behind this is that basically, a search engine will assign a higher ranking to static pages (which are, apparently, less likely to change). (Although I'm not exactly an expert in SEO, I personally don't buy into this idea myself – I'm guesing that with the kind of minds behind Google and Bing's algorithms, it will take slightly more than a fake file extension to con your way you into SERP pole position!)

For more information on naming URIs, I recommend reading these articles:

Tim Berners-Lee:

W3C QA Tips:

Brian Kelly (UK Web Focus / UKOLN - University of Bath):

Hope this helps!

share|improve this answer

I completely agree to all the answers put above. Just adding that one of the reasons why extensions are hidden in URL is to security. Putting it simply, if you don't expose the extension in the URL, it is little hard to figure out the technology on which the application has been built. So lets say a page in made in PHP and the extension is not hidden, then a hacker could potentially figure the vulnerabilities of PHP and use it to execute some malicious activity.

share|improve this answer
I agree with your comment, but I think that using URIs to obfuscate your backend technology as a security measure is useless. At first glance, you are hiding the particular technology used. Unfortunately, the only people this is going to “fool” are the end-users; some (if not most) of which have no idea what a URL is, let alone say ASP/PHP/etc. For lack of a better phrase, you are kind of “preaching to the choir.” – Jordan Clark Mar 31 '14 at 14:28

Totally agree as explain by "Stephen Ostermiller" but I would like to mentioned the trick behind that to hide extension of URLs. And for that you have to use .htaccess rewrite rule, here is the script that help you out:

Redirect external .php requests to extensionless URL

RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.