ErrorDocument 似乎在我的 .htaccess 中不起作用

发布于 2024-09-18 05:44:51 字数 473 浏览 2 评论 0原文

有人可以建议吗?我希望我的网站访问者的默认页面为index.php,对于所有不存在的页面,访问者应该看到errordoc.php

所以我把它放在.htaccess中:

ErrorDocument 404 /errordoc.php

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mysite\.org\.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.org.uk/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

不幸的是,所有内容都会被索引.php,包括错误。我尝试询问我的朋友 Google,但他今天休息!

Can anyone advise please? I'd like to have the default page for visitors to my site as being index.php and for all non-existent pages the visitor should see errordoc.php

So I've put this in the .htaccess:

ErrorDocument 404 /errordoc.php

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mysite\.org\.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.org.uk/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Unfortunately everything is going to index.php, including errors. I've tried asking my friend Google but it's his day off today!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独陪着我 2024-09-25 05:44:51

您的最后一条规则将捕获所有无法映射到现有文件 (RewriteCond %{REQUEST_FILENAME} !-f) 或现有目录 (RewriteCond %{REQUEST_FILENAME} !-d) 的请求)。这就是错误文档不会被提供的原因。

Your last rule will catch all requests that cannot be mapped onto existing files (RewriteCond %{REQUEST_FILENAME} !-f) or existing directories (RewriteCond %{REQUEST_FILENAME} !-d). That’s why the error document will not be served.

雨夜星沙 2024-09-25 05:44:51

该文件中有 2 个不兼容的部分。选择一个
仅保留第一行或仅保留文件的其余部分。但不是两者兼而有之。

下面三行告诉网络服务器将所有不存在的页面定向到index.php,而不是errordoc.php

you have 2 incompatible sections in this file. choose one
leave either only first line or only the rest of the file. But not both.

Bottom three lines tells web-server to direct all non-existent pages to the index.php, not to errordoc.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文