.htaccess 错误文档重定向
我对 Apache 和 .htaccess 非常陌生,我有一个关于如何使用 Apache 的 ErrorDocument 命令处理 403 和 404 错误的简单问题。
让我们看一下我编写的早期 CMS 中的这段代码:
ErrorDocument 404 /admin/includes/access_deny.php?error=404
当用户访问时,这将默默地将他们重定向到 http://www.mysite.com/admin/includes/access_deny.php?error=404
404 错误。
这是我的问题,对于 .htaccess 文件,此错误文档将始终位于同一位置。但是,如果我需要移动我的安装,例如目录子文件夹
,我将需要打开 .htaccess 文件并更新以下内容,以使其正常工作:
ErrorDocument 404 /subfolder/admin/includes/access_deny.php?error=404
有什么办法可以是否有 .htaccess 重定向到此页面 admin/includes/access_deny.php?error=404
就文件本身而言,而不是绝对 URL?另外,无论我将来将安装移动到哪里,Apache 都会捕获与该文件同一级别或子目录中的所有 404 错误。
如果不清楚,请告诉我。
感谢您抽出时间。
I am very new to Apache and .htaccess, and I had a simple question regarding how to handle 403 and 404 errors with Apache's ErrorDocument command.
Let's look at this code from an early CMS I wrote:
ErrorDocument 404 /admin/includes/access_deny.php?error=404
This will silently redirect the user to http://www.mysite.com/admin/includes/access_deny.php?error=404
when they get a 404 error.
Here is my problem, this error document will always be in the same place, with regards to the .htaccess file. However, if I need to move my installation, say to the directory subfolder
, I will need to open the .htaccess file an update the to following, for it to work correctly:
ErrorDocument 404 /subfolder/admin/includes/access_deny.php?error=404
Is there a way I can have .htaccess redirect to this page admin/includes/access_deny.php?error=404
in regards to the file itself, not an absolute URL? Also, no matter where I would move the installation in the future, Apache will catch all 404 errors that are on the same level or sub-directories to this file.
Please let me know if that is not clear.
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 手册 中:
URL 可以以斜线开头 (/ ) 表示本地 Web 路径(相对于 DocumentRoot),或者是客户端可以解析的完整 URL。或者,可以提供一条消息以由浏览器显示。
此线程可能会帮助您修复它。
From the manual:
URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), or be a full URL which the client can resolve. Alternatively, a message can be provided to be displayed by the browser.
This thread may help you fix it though.