代码之家  ›  专栏  ›  技术社区  ›  Piers Karsenbarg

将.html添加到URL结尾

  •  3
  • Piers Karsenbarg  · 技术社区  · 15 年前

    我目前正在使用WordPress作为博客平台,但我想改为使用Jekyll生成静态页面。在WordPress上,我的URL使用以下格式:

    /年/月/日/标题

    但我想把它改为

    /年/月/日/标题.html

    我不知道如何使用mod ou rewrite来实现这一点。

    有人有什么想法吗?

    2 回复  |  直到 7 年前
        1
  •  3
  •   Aron Rotteveel    15 年前
    RewriteEngine On
    # Only if the URI is not a normal file
    RewriteCond %{REQUEST_FILENAME} !-s 
    # ... or a symbolic link
    RewriteCond %{REQUEST_FILENAME} !-l 
    # ... rewrite everything that ends on .html to the stripped down URL
    RewriteRule (.+)\.html$ $1 [L]
    # Alternatively, if you want to be more specific about the scheme, you can use this
    # RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^/]+)\.html$ $1/$2/$3/$4 [L}
    

    上面应该提供一些关于如何正确地将URL重写为您想要的方案的指针。此示例透明地将以.html结尾的所有内容(实际文件除外)重写到同一个URL,而不附加.html。

        2
  •  0
  •   Adam Hopkinson    15 年前

    我相信您只需转到“管理”?“设置”?“永久链接”,并将永久链接设置为“自定义”,值为:

    /%year%/%monthnum%/%day%/%postname%.html