2009-10-08 21 views
0

我想有一個.htaccess文件,可以在我的本地主機開發環境和託管的生產站點上正確重寫。現在我必須爲每個我工作的網站保留兩份單獨的文件副本。我希望能夠同步這兩個網站,而不會吹掉其中一個.htaccess文件。如何編寫一個基於請求url進行不同重寫的.htaccess?

下面是.htaccess文件,我在註釋中使用了一些僞代碼來演示我想要做什麼。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond $1 !^(index\.php|images|robots\.txt|css) 

## IF the url looks like its from localhost then use this rule 
    ## The incoming url might look like: http://localhost/mysite/about 
    RewriteRule ^(.*)$ /mysite/index.php/$1 [L] 
## Else do this rewrite 
    ## The incoming url might look like: http://www.mysite.com/about 
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    ErrorDocument 404 /index.php 
</IfModule> 

這裏是我的服務器配置:

發展:XAMPP在Windows

生產:Dreamhost的

回答

1

我對這個有點生疏,但我認爲:

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] 

#Do your live stuff here 

RewriteCond %{HTTP_HOST} ^localhost$ [NC] 

#Do your local stuff here 
0

使用的RewriteCond檢查%{HTTP_HOST}。例如:

RewriteCond %{REMOTE_HOST} ^localhost$ 
0

我只想用一個單獨的virtual host爲開發環境使用相同的設置作爲您的生產服務器。

只需要添加另外<VirtualHost>容器您的httpd.conf的httpd-vhosts.conf配置文件,並調整設置:

<VirtualHost *:80> 
    ServerName example.com.local 
    DocumentRoot /absolute/filesystem/path/to/your/localhost/mysite 
</VirtualHost> 
+0

然而,這是一個好主意,我喜歡來開發和調試在我本地機器然後上傳更改。 – 2009-10-08 20:04:31