简体   繁体   English

htaccess 404重定向不起作用

[英]htaccess 404 redirect not working

I am trying to setup a custom 404 page for my website using: ErrorDocument 404 /404.html but when I add this, going to domain.com/dslkjflsdkjflskdjf doesn't redirect to the 404 page. 我正在尝试使用以下代码为我的网站设置自定义404页面: ErrorDocument 404 /404.html但是当我添加此页面时,转到domain.com/dslkjflsdkjflskdjf不会重定向到404页面。 Instead, it redirects to my homepage where mostly everything on the page is broken. 相反,它重定向到我的主页,该页面上几乎所有内容都被破坏了。

I'm wondering if this mod_rewrite.c module is the cause of this, I've tried modifying it (taking L out, adding the redirect inside the module, etc) but no luck. 我想知道这是否是mod_rewrite.c模块的原因,我尝试修改它(删除L,在模块内部添加重定向等),但是没有运气。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>

I'm not sure about this but I think your server won't recognize a 404 error because every request is redirected to your index.php. 我对此不确定,但我认为您的服务器无法识别404错误,因为每个请求都重定向到您的index.php。 You have to determine in the index.php if there is a 404 error and send the header with the header() function. 您必须在index.php中确定是否存在404错误,然后使用header()函数发送标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM