1and1 .htaccess 指令:需要解释

1and1 .htaccess directives: explanation needed

我没有修改 .htaccess 文件的经验。 我正在尝试向我的网站添加自定义错误页面,并且我从托管服务提供商 (1and1) 那里获得了以下模板。我知道如何添加页面,但我想逐行了解代码的作用。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errordocument.html
ErrorDocument 400 /errordocument.html
RemoveType x-mapp-php4 .html

提前感谢您的帮助!

让我们从第一行开始:

RewriteEngine On - 非常简单,如名称所示,它使重写引擎能够让我们做很多事情。 (我不会详细说明所有这些东西是什么)

RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d 基本上检查任何不是文件或目录的东西,如果满足这两个条件,它会移动到 RewriteRule 如果不, 那么过去的一切都将是 运行.

RewriteRule (.*) /errordocument.html - 这基本上是告诉服务器如果满足上述条件,则重定向到名为 errordocument.html 的错误页面。 (这当然符合你的上述条件)。

ErrorDocument 400 /errordocument.html - 简单地说,这只是告诉服务器如果收到 400 错误,则显示 errordocument.html 页面。

最后 RemoveType x-mapp-php4 .html - 这基本上是告诉您的 Apache 服务器从您的 URL 末尾删除任何 .html 的扩展名。

要更深入地了解其中的每一项以及它们的使用范围,请单击 here

查看 Apache 文档

我希望这可以帮助您更好地理解正在发生的事情。