【发布时间】:2011-02-15 17:00:35
【问题描述】:
我想确保我网站上的某些 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]
有人对我如何强制登录、注册和帐户页面为 https,同时强制其他所有页面不为 https 有任何建议吗?
【问题讨论】:
-
什么 url 触发了无限重定向?重写日志的输出是什么?
-
你应该知道,通过服务器知道他们在“其他”页面上,SSL的所有辛苦工作已经完成,强制它为非SSL只是额外的工作。跨度>
标签: apache mod-rewrite ssl https