【问题标题】:404 error page not redirected to custom page using htaccess404 错误页面未使用 htaccess 重定向到自定义页面
【发布时间】:2018-04-18 05:20:15
【问题描述】:

我将 404 错误重定向到自定义页面的 htaccess 规则不起作用。 我把下面的代码:

<IfModule security2_module>
    ErrorDocument 404 https://example.com/404.php
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule index\.html$   index.php [L]
</IfModule>

我同时使用了 - ErrorDocument 404 https://example.com/404.phpErrorDocument 404 /404.php

如果有人有解决办法,请告诉我

【问题讨论】:

  • 也许该模块没有加载?尝试从if 语句中删除您的命令
  • 使用 SSH apachectl -M 检查此模块是否实际加载到您的服务器上。

标签: php .htaccess redirect mod-rewrite


【解决方案1】:
ErrorDocument 404 http://jobguide.australianenglishcenter.com/404/

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.php [L]

这里,ErrorDocument 将所有 404 重定向到特定 URL

重写规则将该 URL 映射到您的实际 404.php 脚本。如果您愿意,可以使 RewriteCond 正则表达式更通用,但我认为您必须明确定义要覆盖的所有 ErrorDocument 代码。

【讨论】:

  • 这里,ErrorDocument 将所有 404 重定向到特定的 URL。
猜你喜欢
  • 2016-11-21
  • 2023-03-10
  • 2012-10-01
  • 2015-08-01
  • 2014-12-23
  • 2013-06-09
  • 1970-01-01
  • 1970-01-01
  • 2014-01-19
相关资源
最近更新 更多