如何使用 .htaccess 规则将 .php 重写为 .html?

发布于 2024-09-02 12:00:22 字数 115 浏览 2 评论 0原文

我想使用 .htaccess 规则将 .php 扩展名转换为 .html 扩展名

这是我可以做的事情吗?如果可以,如何做?

I want to convert .php extension to .html extension using .htaccess rules

Is this something I can do, and if so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红衣飘飘貌似仙 2024-09-09 12:00:22
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

使用mod_rewrite。 $1 表示正则表达式的第一部分,[nc] 表示不区分大小写。

您可以看看这篇文章: http:// roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

编辑:
删除了一行。我想你不需要这样。
另外,对我所做的事情发表评论。

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

Uses mod_rewrite. $1 indicates first part of the regex and [nc] means not case sensitive.

You can take a look at this article: http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

EDIT:
Removed a line. You do not need that I think.
Also, commented on what I did.

累赘 2024-09-09 12:00:22

也许尝试一下

RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ $1.html [NC,L]

RewriteRule ^(.*)\.html$  $1.php [NC,L]

Maybe try

RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ $1.html [NC,L]

RewriteRule ^(.*)\.html$  $1.php [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文