【问题标题】:How to add ".html" to wordpress urls in nginx?如何在 nginx 中将“.html”添加到 wordpress url?
【发布时间】:2018-12-16 01:07:44
【问题描述】:

我使用 nginx 和 wordpress。有人黑了一个非常受欢迎的博客帐户,现在我试图在这个网站上生存。我想保护旧地址和永久链接。我进行了一项研究,但由于关于该主题的类似结果而无法找到。抱歉,如果这是重复的。

如何在我的网址后的固定链接后添加.html。我试过这个,但我在浏览器中得到 404。

location / {
    try_files $uri $uri/ @htmlext;
}

location ~ \.html$ {
    try_files $uri =404;
}

location @htmlext {
    #rewrite ^(.*)$ $1.html last;
    rewrite ^(.*)$ $1.html permanent;
}

谢谢

【问题讨论】:

  • 您的问题不清楚。 “仅在浏览器中”是什么意思?是否要将请求 example.com/some/path/ 重写为 example.com/some/path.html?或者将请求example.com/some/path.html 重写为example.com/some/path/?您现在的网站上是否有静态 html 文件而不是 wordpress 核心?
  • 其实我解决了。我不必将“.html”添加到来自 nginx 的 url。 Wordpress 在自定义永久链接中处理它。不确定删除问题或留下问题有人可以搜索类似这样的问题。

标签: wordpress nginx url-rewriting


【解决方案1】:

如果您将 wordpress 与 nginx 一起使用,那么使用 wordpress 设置更改永久链接的最佳方法。我使用此设置来获取我的旧链接/%year%/%monthnum%/%postname%.html

我希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 2018-06-11
    • 2019-02-11
    • 2017-02-17
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    相关资源
    最近更新 更多