簡體   English   中英

Apache Mod_Rewrite

[英]Apache Mod_Rewrite

我正在努力編寫.htaccess文件來基本映射以下域:

  • dev.domain.com/$1 => index.php/dev/$1
  • api.domain.com/$1 => index.php/api/$1
  • domain.com/$1 => index.php/front/$1
  • www.domain.com/$1 => index.php/front/$1

目前,所有內容都使用以下配置映射到index.php/$1

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

這是我默認使用的php框架。 任何幫助將不勝感激:-)謝謝!

如果要根據域名映射請求的路徑,則可以使用其他RewriteCond並首先匹配HTTP_HOST

您必須將每個域的現有RewriteConds和RewriteRule塊相乘 - 除了最后一對可能只是默認值:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^dev\.domain\.com
RewriteRule ^(.*)$ index.php/dev/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^api\.domain\.com
RewriteRule ^(.*)$ index.php/api/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/front/$1 [L]

沒有測試過。 但是,請參閱有關服務器故障的文章, 您想知道的有關Mod_Rewrite規則的一切,但是我們不敢問? ,它解釋了條件和重寫規則之間的相互作用。

暫無
暫無

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

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