Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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
404使用.htaccess重定向_.htaccess_Http Status Code 404 - Fatal编程技术网

404使用.htaccess重定向

404使用.htaccess重定向,.htaccess,http-status-code-404,.htaccess,Http Status Code 404,我想在我的.htaccess文件中设置一个规则,这样,由于没有这样的文件而导致404的任何已插入的url都会自动重新定向到站点的主页: index.php 我的.htaccess文件如下所示: RewriteEngine On RewriteCond %{HTTP_HOST} !^queenslandbeerweek.com.au$ [NC] RewriteRule ^(.*)$ http://queenslandbeerweek.com.au/$1 [L,R=301] ErrorDocumen

我想在我的.htaccess文件中设置一个规则,这样,由于没有这样的文件而导致404的任何已插入的url都会自动重新定向到站点的主页: index.php

我的.htaccess文件如下所示:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^queenslandbeerweek.com.au$ [NC]
RewriteRule ^(.*)$ http://queenslandbeerweek.com.au/$1 [L,R=301]
ErrorDocument 404 /index.php 
这会导致index.php文件显示,但会被破坏,并在地址栏中留下URL

我在另一篇文章的答案中读到,它与将错误的URL作为参数传递有关,导致页面无法正确加载,因为页面调用数据库中的数据,并将错误的URL作为index.php的参数传递,但没有提示解决方案是什么

我希望发生的是,如果在地址栏中键入了错误的URL,或者如果随后出现了指向不存在的文件的链接,则会完全忘记该文件,删除所有内容,然后转到主页index.php

php从数据库调用数据

使用.htaccess文件可以这样做吗

我的另一个网站也有同样的问题

任何帮助都将不胜感激。 干杯,艾尔

ErrorDocument 404 /404.php
你可以把404错误模板放在任何你想要的地方。例如,您可以将所有错误消息放在名为errormessages的文件夹中

ErrorDocument 404 /errormessages/404.php 

我认为您不能直接重定向错误文档,但可以捕获不存在的文件和文件夹

-f
表示不是文件
-d
表示不是目录,
$1
(.*)
中的任何内容(url中的路径)


他已经知道如何设置错误文档,因为你可以看到他在问题中使用了错误文档。他想要的是它被重定向到另一个位置,这样导致404的url就不再显示了。只需设置errordocument,它就可以以相同的404 url.hmmm呈现该文档。这让我思考。我走错方向了吗。我是否应该创建一个自定义的404.php文件,该文件除了立即重定向到home-pagelike:header('location:index.php')之外什么都没有;还是什么?@Almeister9检查我的答案,你必须捕获不存在的文件/文件夹。注意:为了SEO目的和可用性,建议使用404页面,而不是重定向。感谢Patrick在聊天窗口中帮助我。我使用上述方法时没有使用?errorurl=$1,因为我不需要捕捉错误的URL。再次感谢。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php?errorurl=$1 [R=301,L]