【问题标题】:How to format the URL of .html page to remove extension with .htaccess? (Wordpress)如何格式化 .html 页面的 URL 以删除带有 .htaccess 的扩展名? (WordPress)
【发布时间】:2016-09-05 14:35:04
【问题描述】:

所以我在网站的根文件夹(连同 WP)中有一个自定义创建的 .html 页面,我希望能够以标准的 Wordpress URL 格式打开它,换句话说,最后没有 .html 扩展名。

请记住,我对正则表达式或.htaccess一无所知,所以我会给你具体的例子:

当我输入mydomain.com/specialpage 时,我希望它加载mydomain.com/specialpage.html,但保留最初输入的 URL 格式(不带扩展名)

【问题讨论】:

  • 另一种方法是在不修改 .htaccess 的情况下创建一个名为 specialpage 的目录,然后将您的文件作为该目录中的 index.html。

标签: wordpress .htaccess url redirect


【解决方案1】:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(specialpage)/?$ /$1.html [L,NC]

这似乎有效。只需将其置于 Wordpress 附带的其他默认规则之上。

【讨论】:

    【解决方案2】:

    如果你有多个页面,你可以这样做:

    RewriteEngine On
    
    # Check to see if a .html file exists for this request.
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteCond %{REQUEST_URI} !\/$ # Prevent internal recursion
    
    # If so, then use serve that file.
    RewriteRule ^(.+)$ $1.html [NC,L]
    

    关于尾部斜杠的说明:您将无法在此处执行此操作,因为它将包含在请求文件名中,因此会检查 specialpage/.html 是否存在,这不是您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      • 2017-05-08
      相关资源
      最近更新 更多