2010-11-03 44 views
0

我正在努力優化.htaccess文件中的代碼,但是在將子目錄請求的URL從https重寫爲http時遇到問題。這裏是我的嘗試:提煉中的幫助.htaccess

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{SERVER_PORT} =443 
RewriteCond %{REQUEST_URI} !\.(js|css|jpe?g|png|bmp|gif)$ [NC] 
RewriteRule !^dashboard(/.*)?$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

RewriteCond %{SERVER_PORT} =80 
RewriteRule ^dashboard(/.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 

此代碼非常適用於https請求到根網址,但是當一個請求進入,比如說,https://example.com/sub的URL被單獨留在家中,並顯示一個無效證書警告。

我的意圖是重寫除dashboard子目錄以外的所有請求。

回答

0

儘量放在儀表盤子句中的RewriteCond:

RewriteCond %{SERVER_PORT} =443 
RewriteCond %{REQUEST_URI} !\.(js|css|jpe?g|png|bmp|gif)$ [NC] 
RewriteCond %{REQUEST_URI} !>dashboard [NC] 
RewriteRule ^.*$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 
+0

未遂,https://example.com/sub仍然沒有改寫爲http://example.com/sub :(我很好奇將儀表板子句移入RewriteCond的目的是? – 2010-11-03 19:13:58

+0

好的,您是否嘗試使用%{HTTPS} = on而不是服務器端口?您使用什麼模塊來連接服務器https連接,mod_ssl? – Andrew 2010-11-03 19:17:32

+0

%{HTTPS} =就像%{SERVER_PORT} = 443一樣。我相當肯定mod_ssl是用於服務https連接的模塊。 – 2010-11-03 19:30:43