2012-10-19 42 views
1

我有一个网站brosing一些网页时触发HTTPS,我想恢复到HTTP不浏览这些网页的时候,这是我的htaccess:Apache的mod_rewrite的规则,禁用HTTPS/SSL除了一些网页

<IfModule mod_rewrite.c> 

    RewriteEngine on 
    #RewriteBase /myproject/ 

    # toggle www prefix 
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    # redirect favicon requests to the correct favicon.ico 
    RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC] 
    RewriteCond %{THE_REQUEST} favicon\.(ico|png|gif|jpe?g) [NC] 
    RewriteRule (.*) http://mysite/favicon.ico [R=301,L] 

    # hide index.php from root 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] 
    RewriteRule^/%1 [R=301,L] 

    # disable HTTPS when not needed 
    RewriteCond %{HTTPS} on 
    #RewriteCond %{HTTP_REFERER} !^(https)(.*)$ 
    RewriteCond %{REQUEST_URI} !^(.*)/(exception|xyz|pqr)(.*)$ [NC] 
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

    # if a directory or a file exists, use it directly 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # otherwise forward it to index.php 
    RewriteRule . index.php [L,QSA] 
    #RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] 

</IfModule> 

如果我打电话https://host/url重定向工作正常着陆http://host/url,但如果我叫https://host/exception,而不是把它当作是我会被重定向到http://host/index.php

什么是错的?由于


更新与解决方案,希望这将是一个人

<IfModule mod_rewrite.c> 

    RewriteEngine on 
    #RewriteBase /yourbase 

    # hide index.php from root 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] 
    RewriteRule^/%1 [R=301,L] 

    # pass-through so when the rules loop (https), the redirect to index won't get applied 
    RewriteRule index.php$ - [L] 

    # toggle www prefix 
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    # redirect favicon requests to the correct favicon.ico 
    RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC] 
    RewriteCond %{THE_REQUEST} favicon\.(ico|png|gif|jpe?g) [NC] 
    RewriteRule (.*) http://liberos.it/favicon.ico [R=301,L] 

    # disable HTTPS when not needed (but don't rewrite direct files requests) 
    RewriteCond %{HTTPS} on 
    #RewriteCond %{HTTP_REFERER} !^(https)(.*)$ 
    RewriteCond %{REQUEST_URI} !^(.*)/(yourpath|another/path)(.*)$ [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d [OR] 
    RewriteCond %{REQUEST_URI} . 
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

    # if a directory or a file exists use it directly, otherwise forward it to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . index.php 
    #RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] 

</IfModule> 
+0

可能重复[301的.htaccess重定向所有HTTPS访问http除了一个PAGE](http://stackoverflow.com/questions/2079015/htaccess-301-redirect-for-all-https-http-except-one-page) – jww

回答

0

既然你是通过index.php路由的一切,你需要通过传递来创建一个规则循环,所以当有用的,重定向将不会被应用。试着在你的规则列表的最顶端添加此规则:

RewriteRule index.php$ - [L] 
+0

谢谢,这个工作!但现在我必须解决下一个问题:该页面没有完整的https内容,因此浏览器显示不安全内容的警告。 我可以通过启用此注释行来解决此问题 #RewriteCond%{HTTP_REFERER}!^(https)(。*)$ 但使用引用者并不好,因为当我单击一个应该使用http的https链接时,它将不匹配该规则并将保持https直到我点击另一个链接,然后将切换到http –

+0

请注意,我也必须在你的建议规则之前放置从根目录隐藏index.php的部分,否则'https://主机/索引。 php'将可到达,我不想 –

+0

我也解决了这个问题,我发布我的最终htaccess希望将有人帮助 –

0
<IfModule mod_rewrite.c> 

    RewriteEngine on 
    #RewriteBase /yourbase 

    # hide index.php from root 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] 
    RewriteRule^/%1 [R=301,L] 

    # pass-through so when the rules loop (https), the redirect to index won't get applied 
    RewriteRule index.php$ - [L] 

    # toggle www prefix 
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    # redirect favicon requests to the correct favicon.ico 
    RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC] 
    RewriteCond %{THE_REQUEST} favicon\.(ico|png|gif|jpe?g) [NC] 
    RewriteRule (.*) http://liberos.it/favicon.ico [R=301,L] 

    # disable HTTPS when not needed (but don't rewrite direct files requests) 
    RewriteCond %{HTTPS} on 
    #RewriteCond %{HTTP_REFERER} !^(https)(.*)$ 
    RewriteCond %{REQUEST_URI} !^(.*)/(yourpath|another/path)(.*)$ [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d [OR] 
    RewriteCond %{REQUEST_URI} . 
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

    # if a directory or a file exists use it directly, otherwise forward it to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . index.php 
    #RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA] 

</IfModule>