【问题标题】:.htaccess redirect .html to non .html not working.htaccess 将 .html 重定向到非 .html 不起作用
【发布时间】:2021-02-22 19:55:26
【问题描述】:

在我的 .htaccess 中使用它:

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

但该站点显示 404 Not Found,即使我有该文件。

该文件是 ishared.html。重定向有效,但如果您转到 http://headupshouldersback.com/ishared.html

有什么建议吗?谢谢!

编辑:以下在我的网站上给了我 500 服务器错误:

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

【问题讨论】:

  • 所以你想让/ishared 显示/ishared.html 的内容?
  • 是的,这正是我想要的

标签: .htaccess mod-rewrite


【解决方案1】:

重定向后:

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

添加到以下行:

RewriteRule ^(.*) /index.php?page=$1.html [QSA,L]

它会起作用的。如果您请求ishared,这将显示ishared.html 的内容。

编辑:

进入循环,抱歉,你需要使用一些php代码。

index.php:

<?php file_get_contents( (isset($_GET['page'])) ? $_GET['page'] : "error.html"); ?>

【讨论】:

  • 谢谢。我试过了,但它导致我的整个网站出现 500 服务器错误。根据您的建议,我使用新代码编辑了我的首要消息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-24
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 1970-01-01
  • 2019-11-29
相关资源
最近更新 更多