Forum Moderators: phranque

Message Too Old, No Replies

Redirecting non-secure page to secure page

I've tried a few .htaccess methods, but got into an endless loop

         

MatthewHSE

3:55 pm on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a page that really should be secure. But, others may be linking to this page and I can't be sure they're using https instead of just http. So, I want to be able to redirect non-secure requests to the secure location.

I've tried the following in .htaccess:

Redirect 301 /directory/script.cgi https://mydomain.com/directory/script.cgi

It seems that this redirects repeatedly until the redirection limit is exceeded.

Is there any other good way to redirect a non-secure page to the secure location?

Thanks,

Matthew

trillianjedi

4:48 pm on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems that this redirects repeatedly until the redirection limit is exceeded.

Yes it would. The "from" field is a local path, so the redirect is being triggered anytime you go to that page, with or without the "s" after http.

You need to do this using mod_rewrite I think. This thread maybe better off in the Apache Web Server forum.

<Added>
Does this help:-

[webmasterworld.com...]

....?
</Added>

TJ

MatthewHSE

4:55 pm on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, mod_rewrite may be the better choice here. I checked the thread you referenced, and it looks like Msg. 7 may come close to what I need, but it's different enough that I don't know what changes to make. Also it seems to have been intended for use in httpd.conf instead of a .htaccess file (which is all I have access to), and I don't know what changes that might require.

Any further ideas on how to accomplish this would be great!

Thanks,

Matthew

jdMorgan

2:10 am on Dec 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As stated in the other thread, the difference is that in httpd.conf, the URL-paths seen by RewriteRule start with a slash, whereas in .htaccess, they don't have the leading slash.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^directory/script\.cgi$ https://mydomain.com/directory/script.cgi [R=301,L]

Jim