2009-10-08 42 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