2013-07-05 85 views
0

我剛創建了一個網站,其中包含兩個虛擬服務器環境 - 測試和生產。由於生產服務器是向所有人開放,但我只允許我的IP訪問測試環境:Apache虛擬主機目錄條件重定向

<VirtualHost *:80> 
    DocumentRoot /home/xxx/www 
    ServerName testing.xxx.com 
    <Directory /home/xxx/www> 
     Order deny, allow 
     Deny from all 
     Allow from xxx.xxx.xxx.xxx 
    </Directory> 
</VirtualHost> 

的問題是,谷歌已經收錄了我的一些測試環境的網頁和他們在谷歌搜索結果提供。我希望任何IP,但我的訪問testing.xxx.com時,重定向到生產服務器(xxx.com)。我寧願與apache.conf做比.htaccess(因爲git存儲庫衝突)。是否有可能添加條件重定向到Apache配置?

回答

1

您可以在httpd.conf Apache的配置文件使用mod_rewrite特點:

<IfModule mod_rewrite.c> 

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{REMOTE_HOST} !^123\.456\.788 [OR] # exclude your first IP 
RewriteCond %{REMOTE_HOST} !^123\.456\.789 # exclude your second IP 
RewriteRule ^(.*)$ http://production-env.com/$1 [R=301,L] # redirection to production site 

</IfModule> 

或者你可以把這些聲明到您的虛擬主機配置文件的<Directory>部分。

通常,您可以利用mod_rewrite模塊來管理Web服務器的URL路由策略。在使用之前,請確保在Apache中安裝並激活了該模塊。