首页 > 解决方案 > 如何获取 .htaccess 文件的当前路径

问题描述

我想在 .htaccess 文件中设置 404 错误文件的路径,而不是每次更改域时都在其中输入域。

例如 :

这是正常的代码ErrorDocument 404 http://www.example.com/404.php

我想将其设置为ErrorDocument 404 404.php

我的意思是 widthout 域 url 。

.htaccess 中是否有像$_SERVER['HTTP_HOST']php 一样的变量来获取域 url?

当我将 404 代码设置为ErrorDocument 404 404.php它的显示空白页面时,其中的文本仅像“404.php”。

谢谢你的帮助^_^。

标签: .htaccess

解决方案


这就是我在 .htaccess 文件中使用的内容。希望能帮助到你。

# This redirects browsers that experience a 404 error (Not Found) (and others listed)
# to the file "error.php" located in the same directory as your .htaccess file.
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php

推荐阅读