ErrorDocument 似乎在我的 .htaccess 中不起作用
有人可以建议吗?我希望我的网站访问者的默认页面为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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的最后一条规则将捕获所有无法映射到现有文件 (
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.该文件中有 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