Mod_rewite – 做这些重写规则的工作?

请帮助。 你能告诉我这是否是正确的代码来执行以下重写? 我无法像我想的那样testing这个特殊的变化。

该公司在一个Apache实例中有四个域。

我只想影响一个 – test.example.com。

我需要这个块来做下面的事情:

  1. 如果主机是test.example.com,则任何调用/需要转到/admin/index.php
  2. 如果主机是test.example.com,则任何对http的调用都需要转到https
    
     RewriteEngine On
     RewriteBase /
     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}closures
     RewriteRule(。*)https://%{HTTP_HOST}%{REQUEST_URI}
        

林恩,非常感谢

更新:

这样的事情呢?

 RewriteCond%{HTTP_HOST}!^ test \ .lifestylepubs \ .com
 RewriteCond%{HTTPS}closures
 RewriteRule(。*)https://%{HTTP_HOST} $ 1
 RewriteRule ^ / $ /admin/index.php

如果你的Apache服务器提供4个域名,那么我会假设每个域名都在它自己的虚拟主机中。 如果不是的话,那我首先会解决的。

那么你可以把你的重写规则放在适当的虚拟主机configuration中,而不必担心太多。

否则,你的重写规则只需要:

 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