如何获取.htaccess文件的当前路径

时间:2019-08-01 15:58:49

标签: .htaccess

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

例如:

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

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

我的意思是扩展域网址。

.htaccess中是否有变量,例如php中的$_SERVER['HTTP_HOST']以获取域URL?

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

感谢您的帮助^ _ ^。

1 个答案:

答案 0 :(得分:0)

这是我在.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