大网数据广告活动
网站运营与故障问答

Why are extensions often hidden on URLs?

· 52CE 我爱测

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?

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2013-05-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。