我一直在環顧四周(這裏和谷歌),我找不到真正適合我的答案。基本上,我有兩臺物理服務器(一臺開發服務器和一臺生產服務器),我希望能夠在我的git倉庫中使用一個.htaccess文件。有兩個服務器和三個子域的mod_rewrite?
通常情況下,這並不困難,但我有兩個域,example.com
和longexample.com
。我設置了longexample.com
和的dev.longexample.com
CNAME記錄到example.com
(和dev.example.com
)在我的DNS主機,並設置apache服務器名/ ServerAlias兩臺服務器上:
dev server:
ServerName dev.example.com
ServerAlias dev.longexample.com
prod server:
ServerName example.com
ServerAlias longexample.com
ServerAlias www.example.com
ServerAlias www.longexample.com
這是我的.htaccess文件:
Options +FollowSymlinks +Indexes
RewriteEngine on
# RewriteCond %{HTTP_HOST} ^www.longexample.com$ [NC,OR]
# RewriteCond %{HTTP_HOST} ^longexample.com$ [NC,OR]
# RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [R,N]
RewriteCond %{HTTP_HOST} ^dev\.longexample\.com$ [NC]
RewriteRule ^(.*)$ http://dev.example.com/$1 [R,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteCond %{THE_REQUEST} ^GET\ ([^\.]+)\.(html|htm) [NC]
RewriteRule ^([^\.]+)\.(html|htm)$ %1 [R,NC,L]
假設前兩個街區應該重寫prod並開發適當的網址(當一切正常時,我會讓它們成爲301),但它似乎並不奏效。就像現在一樣,它什麼都不做。如果我將RewriteRule設置爲[N]
而不是[L]
,它會給我一個無限循環。
第一個塊被註釋掉了,因爲如果我在開發服務器上工作,那麼prod的解決方案應該是顯而易見的。最後一塊使,以example.com/about.html
請求重定向到example.com/about
(同時仍使用/about.html
文件。這部分工作正常。
是有一些問題,使用兩個域?我也用%{SERVER_NAME}
代替%{HTTP_HOST}
,但沒有試過。改變
你應該接受你的答案,這樣的問題會顯示爲‘已解決’ –
請閱讀clev呃建議從雅虎慢在這裏http://developer.yahoo.com/performance/rules.html並轉到「使用Cookie免費域的組件」一節,你就會明白爲什麼重定向到URL沒有「www 「 –