2012-07-11 92 views
1

我试图迫使3页的网站的SSL,并强制休息到http的.htaccess力HTTPS否则强制HTTP

mydomain.com/register,mydomain.com/checkout和MYDOMAIN .com /感谢所有需要重定向到https:但任何其他页面应该只使用http:

这可能吗?

我现在有一些笨具体的东西在我的htaccess

RewriteEngine on 
RewriteCond $1 !^(index\.php|assets|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

可能重复的 - 例如参见这些问题的答案:http://stackoverflow.com/questions/4192948/remove-www-site-wide- force-https-on-certain-directories-and-http-on-the-rest – Marki555 2012-07-11 17:48:12

+0

它不重复,问题是对的。需要找到CodeIgniter的解决方案....对于CI它不起作用。 – TechCare99 2014-05-17 05:46:40

回答

2

不是的.htaccess的解决方案,但在这里就是我如何强制HTTPS连接:

// Redirect to secure port 
if ($_SERVER['SERVER_PORT'] != 443) 
{ 
    $location = 'Location: https://www.blah.com'; 
    header($location); 
} 

希望这有助于。

+0

如果您使用的是Apache,您应该可以访问许多与SSL相关的变量,在PHP中它们将在$ _SERVER []下显示。这里是列表http://www.modssl.org/docs/2.8/ssl_reference.html#ToC25 – Marki555 2012-07-11 17:50:45

2

我觉得这个代码将工作(专门为CodIgniter)

RewriteEngine on 

# force HTTPS 
RewriteCond %{HTTPS} =off 
RewriteCond %{REQUEST_URI} (register|checkout|thanks) 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# force HTTP 
RewriteCond %{HTTPS} =on 
RewriteCond %{REQUEST_URI} !(register|checkout|thanks|css|img|js) 
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [L] 
+0

感谢哥们。这应该是可以接受的答案:) – Waqas 2016-01-31 19:51:17