Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
如何使用.htaccess将错误404重定向到主页?_.htaccess_Redirect_Web_Http Status Code 404 - Fatal编程技术网

如何使用.htaccess将错误404重定向到主页?

如何使用.htaccess将错误404重定向到主页?,.htaccess,redirect,web,http-status-code-404,.htaccess,Redirect,Web,Http Status Code 404,您好,如何将错误404重定向到带有.htaccess的主页 例如: site.com如果写入site.com/some\u site\u notforund而不是404,则会将我们重定向到主页 例2: sadisic.pl如果写入sadisic.pl/some_site_notfound而不是404,则会将我们重定向到当前页面尝试: FallbackResource /index.html 或者不管主页是什么 尝试: 这对我的网站很好。我试过这段代码,它没有显示404页,但它显示了相同的UR

您好,如何将错误404重定向到带有.htaccess的主页

例如: site.com如果写入site.com/some\u site\u notforund而不是404,则会将我们重定向到主页

例2:
sadisic.pl如果写入sadisic.pl/some_site_notfound而不是404,则会将我们重定向到当前页面

尝试:

FallbackResource /index.html
或者不管主页是什么


尝试:


这对我的网站很好。我试过这段代码,它没有显示404页,但它显示了相同的URL,但主页的内容

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L]
  • 在根目录中创建一个.htaccess文件
  • 将此代码放入其中并自定义重写规则
  • 在我的本地主机上工作得非常好。

    您可以这样做

    这将是.htaccess文件:

    ErrorDocument 404 /404.php
    
    所有未找到的页面将显示404.php文件

    在404.php文件中,您可以编写:

    <?php
        header('location:index.php');
    ?>
    
    
    

    因此,所有未找到的页面都将转到404.php页面,并将它们重定向到index.php,或保存一个重新路由步骤,然后将以下内容放入.htaccess文件中:

    ErrorDocument 404 /404.php
    

    ErrorDocument 404/index.php

    就是这个?ErrorDocument 404/index.htmlHave您是否已经将AllowOverride指令设置为httpd.conf以启用.htaccess?是的,好的,我有这个代码ErrorDocument 404/witout index.html和work@Taizoito您如何允许在ClearOS Web服务器中使用Override?这不适用于我的服务器。如果你写url仍然有效,而不是为了我的目的重新定义sadisic.pl,我希望类似地重定向到sadisic.plenglish@seweryns然后您需要使用mod rewrite,请参见上面的编辑部分
    。htaccess
    这些行必须放在哪个部分?在
    内?还是外部?最好的方法是-
    errordocument404/index.php
    或errordocument404(添加http://infort pls)。它一直被这样的人拿走
    <?php
        header('location:index.php');
    ?>