Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache-.htaccess:mod#u rewrite和ErrorDocument赢得';我们不能一起工作_Apache_.htaccess_Mod Rewrite_Http Status Code 404 - Fatal编程技术网

Apache-.htaccess:mod#u rewrite和ErrorDocument赢得';我们不能一起工作

Apache-.htaccess:mod#u rewrite和ErrorDocument赢得';我们不能一起工作,apache,.htaccess,mod-rewrite,http-status-code-404,Apache,.htaccess,Mod Rewrite,Http Status Code 404,我不确定这里的错误是什么,但我无法将404错误重定向到特定页面。以下是.htaccess的外观: RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+) - [PT,L] RewriteRule ^(.+) index.php ErrorDocument 404 http://www.someurl.com/error404/40

我不确定这里的错误是什么,但我无法将404错误重定向到特定页面。以下是.htaccess的外观:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) index.php

ErrorDocument 404 http://www.someurl.com/error404/404.php
错误文件夹和文件存在,当我执行
curl-I时http://www.someurl.com/notexistent
它返回正确的404错误代码。但是没有重定向,没有卷曲,也没有在浏览器中。这怎么可能? 抱歉,我不是这些方面的专家。htaccess配置,非常感谢您的帮助

编辑1: 我尝试了不同的url,如:

ErrorDocument 404 http://www.someurl.com/error404/
ErrorDocument 404 /error404/404.php
ErrorDocument 404 /error404/
但是没有成功

编辑2:
我忘了提到:mod_重写工作如预期。只有404重定向不起作用。

使用您的
重写规则
将所有没有实际文件或文件夹的页面重写到
index.php
404错误没有例外

尝试:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php? [L,R=404]

使用
RewriteRule
将所有没有真实文件或文件夹的页面重写为
index.php
404错误无例外

尝试:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php? [L,R=404]

谢谢你的回答:)你能帮我解决这个问题吗?不,我不能,如果我不知道你想做什么。。。将所有没有真实文件的页面重写为
index.php
。不要这样做(删除行
RewriteRule^(+)index.php
),如果您喜欢404页面,只需使用
errordocument404
。在哪些情况下,您希望看到404页,在哪些情况下,您希望看到
index.php
??好的,对。我应该说得更具体些。将所有不存在的页面重写为index.php的规则似乎不起作用。当我访问一个不存在的链接时,我只看到一个空白页面,尽管我没有被重定向到index.php或/。所以,我想做的是,当访问一个不存在的文件/文件夹时,a)应该重定向到index.php或/或b)重定向到404页面。我更喜欢a)但是对于我的.htaccess,这两个重定向都不起作用:(现在在回答部分尝试使用我的.htaccess。谢谢!我尝试了,但没有成功:当我删除行
RewriteRule^(+)index.php
将不存在的页面重定向到index.php确实起了作用,但页面的所有真实、现有链接都不再起作用。因此,我今天读了很多关于php的文章,然后查看了index.php。我的理解是,在index.php中有一个“查询”(还不确定这到底是什么),我想我需要修复/排除故障/编辑此查询。因此我必须深入挖掘。我认为这不是.htaccess的问题。非常感谢您的帮助,并提出了正确的问题:)谢谢您的回答:)您能帮我修复此问题吗?不,如果我不知道您想做什么,我不能。。。将所有没有真实文件的页面重写为
index.php
。不要这样做(删除行
RewriteRule^(+)index.php
),如果您喜欢404页面,只需使用
errordocument404
。在哪些情况下,您希望看到404页,在哪些情况下,您希望看到
index.php
??好的,对。我应该说得更具体些。将所有不存在的页面重写为index.php的规则似乎不起作用。当我访问一个不存在的链接时,我只看到一个空白页面,尽管我没有被重定向到index.php或/。所以,我想做的是,当访问一个不存在的文件/文件夹时,a)应该重定向到index.php或/或b)重定向到404页面。我更喜欢a)但是对于我的.htaccess,这两个重定向都不起作用:(现在在回答部分尝试使用我的.htaccess。谢谢!我尝试了,但没有成功:当我删除行
RewriteRule^(+)index.php
将不存在的页面重定向到index.php确实起了作用,但页面的所有真实、现有链接都不再起作用。因此,我今天读了很多关于php的文章,然后查看了index.php。我的理解是,在index.php中有一个“查询”(还不确定这到底是什么),我想我需要修复/排除故障/编辑此查询。因此,我必须深入挖掘。我认为这不是htaccess的问题。非常感谢您的帮助和提出正确的问题:)