homepage Welcome to WebmasterWorld Guest from 54.166.66.204
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess to redirect to https folder
then back to http:// when leaving folder
BenSeb




msg:3150551
 7:56 pm on Nov 8, 2006 (gmt 0)

Hi

Because I have a secure ceckout on my site, I have put some code to redirect anything in the /checkout folder to https://domain.com/checkout (currently using a php redirect). However people then tend to browse around my site using https:// which can cause some issues (I cant serve ads on these pages!)

I would be keen to find a nice htaccess rule, which would do the following:

If user enters any page within: /checkout then redirect to https page
if user enteres any page outside of /checkout then redirec to http page

How could I do this?

Thanks!

 

BenSeb




msg:3150581
 8:18 pm on Nov 8, 2006 (gmt 0)

ok got this far:

in /.htaccess

RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ [test.domain.com...] [R,L]

in /checkout/.htaccess

RewriteEngine on
RewriteCond %{SERVER_PORT}!^443$
RewriteRule ^(.*)$ https://test.domain.com/checkout/$1 [R=301,L]

This works for 99% of cases, except when you load:

[test.domain.com...] (with no trailing slash or filename)

which then goes to:

https://test.domain.com/checkout//home/vhosts/test.domain.com/httpdocs/checkout

Any ideas?

jdMorgan




msg:3150658
 9:46 pm on Nov 8, 2006 (gmt 0)

No idea if this will help, but there's a serious logic error that needs to be fixed before proceeding. The problem is caused by the fact that the main /.htaccess will be processed for all requests, including requests to /checkout. As a result, the code in /.htaccess needs to know not to rewrite https /checkout requests to http:

In /.htaccess

RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteCond $1 !^checkout
RewriteRule (.*) http://test.domain.com/$1 [R,L]

Jim

nakulgoyal




msg:3150674
 9:55 pm on Nov 8, 2006 (gmt 0)

Jim, I am not saying you are wrong. But tell me if I am wrong please. Does the child folder .htaccess not overwrite all parent folder commands? What if your host has something in /home folder? Does our .htaccess in our home folder overwrite any settings in there?

BenSeb




msg:3150727
 10:47 pm on Nov 8, 2006 (gmt 0)

with that amend it works fine :) Cheers

the only problem is, the images css and js files are rewritten back to http:// because they are not in the checkout folder!

Can we get a slight amend so that it only redirects actual pages rather than the images, etc?

would need to deal with php pages (and obviously domain.com/ where pagename is not shown..,)

Ben

jdMorgan




msg:3150736
 10:52 pm on Nov 8, 2006 (gmt 0)

nakulgoyal,

Overwrite? No. The top-level rewrites will be invoked, followed by the lower-level rewrites, but both will occur. And since an external redirect is involved, that's not good.

Ben,

You should be able to add an exclusion to the /checkout/.htaccess file, in much the same way as I showed for the /.htaccess exclusion.

I'm not clear on all the exclusions you might need, but the pattern for css and js files would be something like

!\.(css¦js)$

Note: No start anchor, because we're only looking at the .js or .css suffix, and you must replace the broken pipe "¦" character shown with a solid pipe character from your keyboard; Posting on this forum modifies the pipe characters.

Jim

BenSeb




msg:3150750
 11:03 pm on Nov 8, 2006 (gmt 0)

Thanks jim

I'll try this. But should the exclusion go in the /.htaccess file, as the images etc are within the /images folder, and it is this htaccess file which is rewriting https > http?

Ben

jdMorgan




msg:3150783
 11:43 pm on Nov 8, 2006 (gmt 0)

I don't know how your site is set up. I encourage you to experiment, though, as this is a discussion forum [webmasterworld.com], not a help desk, and the only way to learn is to try. :)

Jim

nakulgoyal




msg:3150949
 3:31 am on Nov 9, 2006 (gmt 0)

Thanks Jim, for clarifying. I appreciate your time.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved