2014-01-12 50 views
2

我怎麼能夠通過.htaccess打開https到所有頁面,但沒有FrontPage任何人都可以幫助我與rewritecond請。.htaccess RewriteCond排除首頁

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR] 
    RewriteCond %{HTTPS} !=on 
    RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=302,L] 


    # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

我已經都這樣了,我的目標是要排除FRONTPAGE爲HTTPS,只有內/子頁面應該有HTTPS。

請幫我修改我現有的一個。謝謝。

回答

0

您可以使用這些規則:

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.+)$ https://www.mydomain.com/$1 [R=301,L,NE] 

RewriteCond %{HTTPS} on 
RewriteRule ^$ http://www.mydomain.com/ [R=301,L] 

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !=/favicon.ico 
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

.+而不是.*確保HTTP是強制執行,除了頭版其他子頁面。

+0

謝謝,如果有人訪問https://mydomain.com或https://www.mydomain.com,它會將其更改爲http://,如果有人使用https://訪問首頁將強制轉到http://唯一的首頁,其餘的應該保留其https:// – axscode

+0

是的,確保可以完成。在我更新的答案中添加了該規則。 – anubhava

+0

非常感謝,完美的作品 – axscode