Many times I see that URL extensions are hidden (e.g.
.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?
There are several reasons to remove extensions from URLs:
Keep in mind that many sites are generated by a content management system (CMS) that would make URLs look like this:
Extensions are not needed on the web because servers send the type of document as a header. Web pages are served as
Some webmasters choose to use an extension on their URLs that matches this content type. So any
There is also the question as to whether URLs might be better ending in trailing slash (
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
If the default file name on your web server is
If there is no trailing
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.
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:
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
*(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:
However, the webmaster will perform a rewrite to make the URI “look” static, such as:
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:
W3C QA Tips:
Brian Kelly (UK Web Focus / UKOLN - University of Bath):
Hope this helps!
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.
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: