我应该如何在我的 .htaccess 文件中编写这些重写规则

How should I write these rewrite rules in my .htaccess file

我的 .htaccess 文件中有这个:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^admin\.domain1\.com$ [OR]
RewriteCond %{HTTP_HOST} ^admin\.domain2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^admin\.domain3\.com$
RewriteRule (.*) /path/to/directory/ [L]

RewriteCond %{HTTP_HOST} ^admin\.domain4\.com$
RewriteRule (.*) /different/path/ [L]

第一个块有效,但第二个块给我以下错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.29 (Ubuntu) Server at admin.domain4.com.ar Port 80

我做错了什么??

The first block works, but the second block gives me an Internal Server error:

两者 rules/blocks 都有相同的“问题”。只有在 /path/to/directory/ 中有另一个 .htaccess 文件也使用 mod_rewrite(可能路由 URL?),第一条规则才会“起作用”,以防止内部重写循环(您的内部服务器错误的可能原因)。

如果您使用的是 Apache 2.4,解决此问题的最简单方法是简单地使用 END 标志,而不是 L。例如:

RewriteRule (.*) /different/path/ [END]

L标志只停止本轮处理,不停止重写引擎的所有处理。在第二次通过重写引擎时,模式 (.*) 也与重写请求 /different/path/<url> 匹配,后者被进一步重写为 /different/path/different/path/<url> 等,导致无限循环,除非有什么可以停止它。