【发布时间】:2019-02-18 18:25:14
【问题描述】:
我正在尝试建立一个曾经在 wordpress 上设置但现在是平面文件的网站。平面文件都是根文件夹中的 .html 文件,我需要进行 htaccess 重写,以便像 mysite.com/test 和 mysite.com/test/ 这样的 url 被同等对待,但也提供 .html与 url 匹配的文件(例如,在请求 mysite.com/test、mysite.com/test/、mysite.com/test.html 等时提供 mysite.com/test.html)。
这是我正在尝试的代码,除了用户请求 mysite.com/test/(带有尾部斜杠)之外,它可以获取所有内容。
期望的结果: mysite.com/test, mysite.com/test/, mysite.com/test.html ALL serve test.html (但url通常不带html扩展名)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
【问题讨论】:
标签: .htaccess