Apache 如何强制某些URL使用SSL,而强制所有其他URL使用非SSL?

Apache 如何强制某些URL使用SSL,而强制所有其他URL使用非SSL?,apache,mod-rewrite,ssl,https,Apache,Mod Rewrite,Ssl,Https,我想确保我的站点上的某些URL总是通过HTTPS访问,而所有其他URL都是通过HTTP访问的 我可以在.htaccess文件中使用这两种情况,但是如果我同时启用这两种情况,则会得到无限的重定向 我的.htaccess文件是: <IfModule mod_expires.c> # turn off the module for this directory ExpiresActive off </IfModule> Options +FollowSymLinks AddH

我想确保我的站点上的某些URL总是通过HTTPS访问,而所有其他URL都是通过HTTP访问的

我可以在.htaccess文件中使用这两种情况,但是如果我同时启用这两种情况,则会得到无限的重定向

我的.htaccess文件是:

<IfModule mod_expires.c>
# turn off the module for this directory
ExpiresActive off
</IfModule>

Options +FollowSymLinks
AddHandler application/x-httpd-php .csv

RewriteEngine On

RewriteRule ^/?registration(.*)$ /register$1 [R=301,L]

# Force SSL for certain URL's
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (login|register|account)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force non-SSL for certain URL's
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(login|register|account)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Force files ending in X to use same protocol as initial request
RewriteRule \.(gif|jpg|jpeg|jpe|png|ico|css|js)$ - [S=1]

# Use index.php as the controller
RewriteCond %{REQUEST_URI} !\.(exe|css|js|jpe?g|gif|png|pdf|doc|txt|rtf|xls|swf|htc|ico)$ [NC]
RewriteCond %{REQUEST_URI} !^(/js.*)$
RewriteRule ^(.*)$ index.php [NC,L]

#关闭此目录的模块
过期活动关闭
选项+FollowSymLinks
AddHandler应用程序/x-httpd-php.csv
重新启动发动机
重写规则^/?注册(.*)$/注册$1[R=301,L]
#强制特定URL的SSL
重写条件%{HTTPS}关闭
重写cond%{REQUEST_URI}(登录|注册|帐户)
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[R=301,L]
#强制某些URL的非SSL
在上重写cond%{HTTPS}
重写cond%{REQUEST_URI}!(登录|注册|账户)
重写规则^(.*)$http://%{http_HOST}%{REQUEST_URI}[R=301,L]
#强制以X结尾的文件使用与初始请求相同的协议
重写规则\(gif | jpg | jpeg | jpe | png | ico | css | js)$-[S=1]
#使用index.php作为控制器
重写条件%{REQUEST\u URI}!\。(exe | css | js | jpe | g | gif | png | pdf | doc | txt | rtf | xls | swf | htc | ico)$[NC]
重写cond%{REQUEST_URI}^(/js.*)$
重写规则^(.*)$index.php[NC,L]

有人对我如何强制登录、注册和帐户页面为https,同时强制其他页面为https有什么建议吗?

似乎您正在为SSL匹配https=on,为未加密连接匹配https=off

您应该仔细检查HTTPS环境变量是否按预期设置。否则将有一个无限的重定向-正如你正在经历的那样


例如:

什么url触发了有限的重定向?重写日志的输出是什么?您应该知道,当服务器知道它们位于“其他”页面时,SSL的所有艰苦工作都已完成,而强制它使用非SSL只是额外的工作。