Forum Moderators: phranque

Message Too Old, No Replies

Avoiding recursion forcing http to https

Redirect http to https in .htaccess on Rackspace

         

mhernandez

8:39 am on Nov 14, 2009 (gmt 0)

10+ Year Member



Hi, here is my first post and new to the .htaccess world so bear with my noobiness.

I've spent 4 hours looking for this and I keep getting recursion.

Everywhere the simplest solution to force a folder to be https is:


RewriteCond %{https} =off
RewriteRule ^(.*) https://%{SERVER_NAME}/folder/$1 [R=301,L]

I installed the .htaccess inside the folder I want to force https and I don't know why but I keep getting and error saying that there were too many redirects trying to access the page.

What can I be missing?

Thanks for the help.

mhernandez

9:52 am on Nov 14, 2009 (gmt 0)

10+ Year Member



It seems that the condition to determine if the request is HTTPS is not working so that is why it keeps looping.

I also tried:

RewriteCond %{SERVER_PORT} !^443

instead of,

RewriteCond %{https} =off

And the problem persists. The redirection to https occurs but becomes recursive.

Why is that RewriteCond not working? any ideas?

mhernandez

10:05 am on Nov 14, 2009 (gmt 0)

10+ Year Member



Still not working.. now in the wee hours and bugged eyed..

Similar problem on thread [webmasterworld.com...] with infinite looping not sure if it got resolved for the original poster bu not for me..

What could be happening?

mhernandez

11:10 am on Nov 14, 2009 (gmt 0)

10+ Year Member



Fixed oh yeah!

I was right. My server (Rackspace.com) was not recognizing RewriteCond %{SERVER_PORT} !^443 because it uses a different system.

From their wiki -> [cloudsites.rackspacecloud.com...]

Answer:


#Force SSL on a specific directory
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/DIRNAMEHERE/ [R,L]

Why in the world they use %{ENV:HTTPS} ?

jdMorgan

4:00 pm on Nov 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like they're paranoid about exposing the standard cgi variable names for some reason...

If you want search engines to list only https URLs, then be sure to use [R=301] as you did in your initial attempts -- The Rackspace code will do a 302 by default, and search engines won't update your URLs to https as a result of that.

They appear to be dropping the requested URL-path as well, since there is no "$1" back-reference in their substitution URL.

Also, "RewriteBase /" is the default, and not needed unless you have previously set it to some other path.

Jim

mhernandez

7:43 pm on Nov 14, 2009 (gmt 0)

10+ Year Member



Thanks Jim,

I added [R=301] and the "$1" I added last night for it to work.

BTW: I am impressed with your dedication to this forum!
You "joined" it back in 2002, that is 2,785 days ago and have 21,828 posts. That is almost 8 posts a day for the last 7 years!
Congratulations and thanks so much for your incredible dedication!