Forum Moderators: phranque

Message Too Old, No Replies

Redirect just Homepage to non-SSL

         

tzflorida

9:48 pm on Dec 2, 2008 (gmt 0)

10+ Year Member



I am using Joomla and want to force just the homepage of my site to always use non-SSL. Any other page should not be affected by that.

Can this be done via .htaccess?

g1smd

12:14 am on Dec 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It should be possible.

tzflorida

1:21 am on Dec 3, 2008 (gmt 0)

10+ Year Member



Do you know how? ;-p

jdMorgan

12:24 am on Dec 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it with mod_rewrite, using a RewriteCond to test SERVER_PORT for 443, and if 443, then redirect a requested URL-path of /index.whatever or a blank URL-path to the same URL-path, but specifying the http: protocol.

Please see our Apache Forum Charter [webmasterworld.com] for information about how to get the most from this forum, and try a search on WebmasterWorld for SSL, 443, RewriteCond SERVER_PORT, and RewriteRule in various combinations to turn up some very recent threads on rewriting/redirecting SSL requests. Then try to modify the code you find to suit your needs, and post back here if you have any trouble.

As described in our Charter, we're happy to help you write *your* code and test and fix problems, but we cannot write the code for you; Such activity is simply not sustainable given the few contributors and many requestors we have here, and the fact that server-side code is simply not a one-size-fits-all, cut-and-paste proposition. Our Charter also contains links to several useful resources.

Thanks,
Jim

tzflorida

5:26 am on Dec 8, 2008 (gmt 0)

10+ Year Member



This is what I came up with:

RewriteCond %{HTTP_REFERER} !^https://www.mysite.com [NC]
RewriteRule (.*) [mysite.com...] [L,NC]

Unfortunately it makes my site completely inaccessible.

What I'd like this code to do is redirect any https requests for the homepage only to http.

jdMorgan

3:44 pm on Dec 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You ignored my statement that you need to check the requested server port (you're testing the referrer instead), and you are not specifying that only the homepage should be redirected...

You'll likely have better luck with something like this:


RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(index\.html)?$ http://www.example.com/ [R=301,L]

Change "index.html" to the name of your homepage, escaping the literal period as shown, and leaving all else the same. The pattern as shown will match requests for example.com/ or example.com/index.html.

Jim

tzflorida

3:58 pm on Dec 8, 2008 (gmt 0)

10+ Year Member



Sorry jdMorgan... I did see what you wrote but thought since index.html is often left out from the URL of the homepage, that I needed to use a Referrer.

I have absolutely no idea about Apache coding :-)

Your solution works flawlessly though... thanks for taking the time to help me.