1

我正在尝试在网站的 3 个页面上强制 SSL,并将其余页面强制为 http

mydomain.com/register 、 mydomain.com/checkout 和 mydomain.com/thanks 都需要重定向到 https: 但任何其他页面都应该只使用 http:

这可能吗?

我目前在我的 htaccess 中有一些 codeigniter 特定的东西

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

2 回答 2

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] 
于 2014-05-17T06:20:16.160 回答
2

不是 .htaccess 解决方案,但这是我强制 https 连接的方式:

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

希望这可以帮助。

于 2012-07-11T16:26:59.670 回答