【问题标题】:404 error htaccess not working404 错误 htaccess 不工作
【发布时间】:2018-06-12 09:14:31
【问题描述】:

我正在尝试将 404 错误重定向到自定义 php 页面 404.php。

我在我的 .htaccess 文件中使用此代码,但它似乎不起作用。谁能指出我可能做错了什么?

Options -Multiviews

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php 
RewriteRule ^s/([^/]*)$ /s.php?share=$1 [L]

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
ErrorDocument 404 /404.php

【问题讨论】:

  • 什么不起作用?它不会重定向或重定向,但会显示错误 404 消息,您不希望这样吗?
  • 尝试将ErrorDocument 404 /404.php 放在所有内容之上(如在Options -Multiviews 之上)。它可能认为这是您的 RewriteCond 规则的一部分。
  • @Fred-ii- 我做到了,但还是不行
  • @Prix 它不会重定向。它显示 apaches 默认未找到页面
  • @KwaasiDjin 你在/home/youraccount/public_html 文件夹中有404.php 文件吗?

标签: php apache .htaccess mod-rewrite


【解决方案1】:

将 ErrorDocument 行放在所有内容之上。

并且:afaik 需要重新启动服务器才能重新读取 .htaccess 并在其中应用任何更改(重新加载将不起作用)。

您是否重新启动了服务器?

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 2018-06-18
    • 1970-01-01
    • 2015-02-15
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    相关资源
    最近更新 更多