Forum Moderators: phranque

Message Too Old, No Replies

Mod_Rewrite HELP

         

smcmor

12:15 am on Aug 19, 2004 (gmt 0)

10+ Year Member



I am trying to use mod_rewrite, have it enabled and so on.

What I want to is be able to enter a particular directory in ssl and whenever i leave that directory exit ssl. I am using phpnuke, this is a particular module and the directory location is /html/modules/giftlist

I have tried a few things in httpd.conf and didn't really get anything working

eg.
RewriteCond %{SERVER_PORT}!^443$
RewriteRule ^(.*)$ [192.168.0.1...] [R,L]

would really appreciate some help please?

jdMorgan

1:04 am on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



smcmor,

Welcome to WebmasterWorld!

> I want to is be able to enter a particular directory in ssl and whenever i leave that directory exit ssl

This would require state transition information that is not available to the server. You can, however, implement it with some code changes as: "I want to use SSL while in a particular subdirectory and whenever not in that subdirectory exit SSL."


# "Enter" SSL
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^html/modules/giftlist(.*)$ https://example.com/html/modules/giftlist$1 [R=301,L]

# "Leave" SSL
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/html/modules/giftlist
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I'm assuming that the "SSL" subdirectory is located at /html/modules/giftlist/ in relation to the document root (home page directory) of your site.

Jim

smcmor

2:09 am on Aug 19, 2004 (gmt 0)

10+ Year Member


thanks for the help jdMorgan

here is what i put into httpd.conf as u suggested.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteLog logs/https_rewrite_log
RewriteLogLevel 1

# "Enter" SSL
RewriteCond %{SERVER_PORT}!^443$
RewriteRule ^/html/modules/giftlist(.*)$ https://192.168.0.1/html/modules/giftlist$1 [R=301,L]

# "Leave" SSL
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI}!^/html/modules/giftlist
RewriteRule (.*) http://192.168.0.1/$1 [R=301,L]
</IfModule>

This code works fine and enables SSL when entering the directory /html/modules/giftlist but i'm afraid when i leave the directory it doesn't exit SSL and go back to ordinary http. Any ideas, I tried playing about with

RewriteCond %{REQUEST_URI}!^/html/modules/giftlist
RewriteRule (.*) http://192.168.0.1/$1 [R=301,L]

by changing various bits at a time, restarting server and still no joy

jdMorgan

3:08 am on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I thought we were using .htaccess, so the rule needs to change slightly:

RewriteCond %(SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/html/modules/giftlist
RewriteRule [b]^/[/b](.*) http://192.168.0.1/$1 [R=301,L]

If that still does not work, then try this as an experiment only:

RewriteCond %(SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/html/modules/giftlist
RewriteRule ^/(.*) http://192.168.0.1[b]:80[/b]/$1 [R=301,L]

The first version should work, but if it doesn't, there's probably some behind-the-scenes stuff going on for SSL, and the second version is meant as a test to help ferret it out.

Jim

smcmor

11:02 am on Aug 19, 2004 (gmt 0)

10+ Year Member



Hi Jim, I tried both your suggestions there and no joy.

I am going to just hardcode the exiting of ssl into my website code. Originally i wanted the Giftlist directory to be SSL and people can buy items of a gift list, credit card etc. So once theyre done i will just link back to index with [......]