gpt4 book ai didi

html - 如何从 URL 中删除 .html?

转载 作者:技术小花猫 更新时间:2023-10-29 11:28:51 24 4
gpt4 key购买 nike

如何从静态页面的 URL 中删除 .html

此外,我需要将任何带有 .html 的 url 重定向到没有它的 url。 (即 www.example.com/page.htmlwww.example.com/page )。

最佳答案

我想对 Jon's answer 做一些解释将是建设性的。以下内容:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

检查如果指定的文件或目录分别不存在,则重写规则继续:

RewriteRule ^(.*)\.html$ /$1 [L,R=301]

但这意味着什么呢?它使用 regex (regular expressions) .这是我之前做的一些小东西...... enter image description here

认为是正确的。

注意:在测试您的 .htaccess 时,不要 使用 301 重定向。使用 302 直到完成测试,因为浏览器将缓存 301s。参见 https://stackoverflow.com/a/9204355/3217306

更新:我有点误会了,. 匹配除换行符之外的所有字符,因此包括空格。另外,here is a helpful regex cheat sheet

来源:

http://community.sitepoint.com/t/what-does-this-mean-rewritecond-request-filename-f-d/2034/2

https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules

关于html - 如何从 URL 中删除 .html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5730092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com