问题原文
原帖链接 · Unknown · CC BY-SA 3.0
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?
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
