开发者

How do I force SSL for some URLs and force non-SSL for all others?

I'd like to ensure that certain URLs on my site are always accessed via HTTPS while all other URLs are accessed via HTTP.

I can get either case working in my .htaccess file, however if I enable both, then I get infinite redirects.

My .htaccess file is:

<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 %{R开发者_JS百科EQUEST_URI} !^(/js.*)$
RewriteRule ^(.*)$ index.php [NC,L]

Does anyone have any suggestions on how I can force the login, register and account pages to be https while forcing every other page to not be?


It seems you are matching HTTPS=on for SSL and HTTPS=off for unencrypted connections.

You should double check that HTTPS environment variable is being set as you expect. Otherwise there will be an infinite redirect - as you are experiencing.

For example: https://issues.apache.org/bugzilla/show_bug.cgi?id=50581

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜