【问题标题】:How to show HTML website URLs like wordpress [duplicate]如何显示 HTML 网站 URL,如 wordpress [重复]
【发布时间】:2014-03-01 22:03:42
【问题描述】:

我正在为我的个人需求创建一个网站。我有不同的页面,如index.htmlabout.htmlcontact.html 等... 默认显示方式为mysite.com/index.htmlmysite.com/contact.html

但是有什么办法可以隐藏扩展部分.html,只显示像mysite.com/about/mysite.com/contact/这样的url正文??

请给我建议。

【问题讨论】:

  • mysite.com/about/ 通常与 mysite.com/about/index.html 相同(取决于服务器设置)。对于更动态的方法,您将使用 URL 重写en.wikipedia.org/wiki/Rewrite_engine
  • @deceze,谢谢你也注意到我这个帖子!

标签: url pretty-urls


【解决方案1】:

可以通过 mysite.com/about/ 显示您的页面

  1. 您需要将所有文件名替换为index.html
  2. 例如:about.htmlindex.html
  3. 将 index.html 添加到各自的页面,如

之前:

万维网/ | |-about/about.html | |-contact/contact.html | |-etc/etc.html

之后:

万维网/ | |-关于/index.html | |-contact/index.html | |-etc/index.html

现在,当您点击 URL www.yourSite.com/about 时,将显示该页面。 (没有 about.html 部分)

【讨论】:

  • -1。抱歉,这是一个非常糟糕的建议。
  • 他没有提到任何服务器端的 URL 重写,所以我相信基本的 OP 就是这个!
  • OP 是否提到它无关紧要。这是一个糟糕的解决方案。
  • OP 没有提到它,因为他可能不知道。你的意图是好的,但远非最佳
  • 这个OP到底是什么??输出?
【解决方案2】:

您必须使用 URL 重写引擎,像这样编辑(或创建).htaccess:

# Remove .html from url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

更多详情:Remove .html from URLs with a redirect

【讨论】:

  • 添加到这个答案,你的网络服务器必须支持 url 重写。对于 Apache(最常用的之一),您必须安装一个名为 mod_rewrite 的模块。对于其他 Web 服务器,请查看文档是否支持。
  • 好的,我会检查的。
猜你喜欢
  • 2015-12-14
  • 1970-01-01
  • 1970-01-01
  • 2017-10-01
  • 2018-07-30
  • 1970-01-01
  • 2019-04-09
  • 2017-09-13
  • 2019-06-29
相关资源
最近更新 更多