我想有一個.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的
然而,這是一個好主意,我喜歡來開發和調試在我本地機器然後上傳更改。 – 2009-10-08 20:04:31