簡體   English   中英

我應該如何在我的 .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/$1 [L]

RewriteCond %{HTTP_HOST} ^admin\.domain4\.com$
RewriteRule (.*) /different/path/$1 [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

我究竟做錯了什么??

第一個塊有效,但第二個塊給了我一個內部服務器錯誤:

兩個規則/塊都有相同的“問題”。 只有在/path/to/directory/中有另一個.htaccess文件也使用 mod_rewrite (可能是路由 URL?)以防止內部重寫循環(您的內部服務器錯誤)。

如果您使用的是 Apache 2.4,解決此問題的最簡單方法是簡單地使用END標志,而不是L 例如:

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

L標志只停止當前輪次處理,它不會停止重寫引擎的所有處理。 在第二次通過重寫引擎時,模式(.*)還匹配重寫的請求/different/path/<url>進一步重寫為/different/path/different/path/<url>等,從而導致無限循環,除非有什么可以阻止它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM