【问题标题】:Redirect all *.php pages to *.html through .htaccess [closed]通过 .htaccess 将所有 *.php 页面重定向到 *.html [关闭]
【发布时间】:2016-10-29 09:00:02
【问题描述】:

我有一个 html 网站,我想将所有 php pages 重定向到 html pages

如何通过htaccess将一些php页面改写成html页面。我有大约 8000 个 html 页面和 500 个 php 页面。我想将 php 页面重写为 .htm。我在 htaccess 中添加了一些代码,但我们的 html 页面无法正常工作。它只显示菜单字段和内页不可见。

我正在使用以下代码-

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php
RewriteRule ^(.*)\.htm$ $1.php

【问题讨论】:

  • 你有什么问题?
  • 在你的代码中交换.php.html 的位置有什么作用吗?比如RewriteRule ^(.*)\.php$ $1.html?

标签: php html .htaccess


【解决方案1】:

确保启用了 mod 重写

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

如果还需要将每个php页面重定向到html

RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1.html [L,R=301]

【讨论】:

  • 嗨艾伦,我在 htaccess 中使用了这段代码,但没有正确重定向。
猜你喜欢
  • 1970-01-01
  • 2013-09-12
  • 2011-11-04
  • 2012-01-02
  • 1970-01-01
  • 2012-10-29
  • 1970-01-01
  • 2016-07-20
相关资源
最近更新 更多