
請幫忙。您能告訴我這是否是執行以下重寫的正確程式碼?我無法像我希望的那樣測試這個特定的更改。
該公司在一個 apache 實例中有四個域。
我只想影響一個 - test.example.com。
我需要這個區塊來執行以下操作:
- 如果主機是 test.example.com,任何對 / 的呼叫都需要轉到 /admin/index.php
- 如果主機是 test.example.com,則任何對 http 的呼叫都需要前往 https
重寫引擎開啟 重寫庫 / RewriteCond %{HTTP_HOST} !^test\.example\.com RewriteRule ^/admin/index\.php$ - [L] RewriteCond %{HTTP_HOST} !^test\.example\.com RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 重寫規則。 /admin/index.php [L] RewriteCond %{HTTP_HOST} !^test\.example\.com RewriteCond %{HTTPS} 已關閉 重寫規則 (.*) https://%{HTTP_HOST}%{REQUEST_URI}
非常感謝,林恩
更新:
像這樣的事情怎麼樣?
RewriteCond %{HTTP_HOST} !^test\.lifestylepubs\.com RewriteCond %{HTTPS} 已關閉 重寫規則 (.*) https://%{HTTP_HOST}$1 重寫規則 ^/$ /admin/index.php
答案1
如果您的 apache 伺服器服務於 4 個網域,那麼我會假設每個網域都位於自己的虛擬主機中。如果沒有,這就是我要解決的第一件事。
然後您可以將重寫規則放入適當的虛擬主機配置中,而不必擔心太多。
否則你的重寫規則只需要:
RewriteCond %{SERVER_NAME} =test.example.com
RewriteRule ^/$ /admin/index.php [L]
RewriteCond %{SERVER_NAME} =test.example.com
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}$1