Forum Moderators: phranque

Message Too Old, No Replies

multiple rewrites

HTTP and HTTPS sections

         

therealgtron

6:18 pm on Dec 5, 2007 (gmt 0)

10+ Year Member



i hate staring my first post w/a help question but i'm feel like im close and really dont have time to research this. lol

any incite would be great...

basicly, i have a number of forms and/or sections that need to use https but after they leave the form i would like it to go back to http so this is what i have so far...

# CRM should be a secure form. Redirect.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^CRM(.*) [%{HTTP_HOST}%{REQUEST_URI}...] [r=301,nc]

# RA Inquiry should be a secure form. Redirect.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)82(.*)$ [%{HTTP_HOST}%{REQUEST_URI}...] [r=301,nc]

# If a member leaves the RAI or CRM, make sure we're no longer in secure form. Redirect.
RewriteCond %{SERVER_PORT}!^80$
RewriteCond %{REQUEST_URI}!^(.*)CRM(.*)
RewriteCond %{REQUEST_URI}!^(.*)82(.*)
RewriteRule ^(.*) [%{HTTP_HOST}%{REQUEST_URI}...] [R,L]

Am i on the correct path? i have about six more pages that need to go to https and back again and dont wanna add them all if i'm not on the correct path.

your help is appreciated. :)

[edited by: tedster at 11:38 pm (utc) on Dec. 5, 2007]

gergoe

6:44 pm on Dec 5, 2007 (gmt 0)

10+ Year Member



Looks to be fine, only I'd add the Last modifier to each RewriteRule's, and I'd combine the different files/paths into one regular expression using the
((CRM)¦(82))
syntax.

I think filtering such a texts in the whole URL is rather risky, if a "82" appears anywhere in the url, it will be redirected, I'd rather anchor it to the path much more, like:

^.*/((CRM)¦(82))/.*$
or
^((CRM)¦(82))/.*$
, depending on how your URL looks like, and you will put that into a .htaccess file or not.

Just a note; if you do not want to capture any substrings with the regular expressions you don't need to enclose the .* expression with brackets, that is only needed if you want to work with the text captured by that expression.

therealgtron

7:45 pm on Dec 5, 2007 (gmt 0)

10+ Year Member



^ thank you :)

something weird though. i changed it to the following and it forces it all to http instead of https

# CRM & 82 should be a secure form. Redirect.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*/((CRM)¦(82))/.*$ [%{HTTP_HOST}%{REQUEST_URI}...] [R,L]

# If a member leaves the CRM or RA, make sure we're no longer in secure form. Redirect.
RewriteCond %{SERVER_PORT}!^80$
RewriteCond %{REQUEST_URI}!^.*/((CRM)¦(82))/.*$
RewriteRule ^(.*) [%{HTTP_HOST}%{REQUEST_URI}...] [R,L]

so now when i put in [example.com...] it forces it back to http. i know i'm just missing something simple here. lol

[edited by: tedster at 11:40 pm (utc) on Dec. 5, 2007]
[edit reason] switch to example.com [/edit]

gergoe

11:22 pm on Dec 5, 2007 (gmt 0)

10+ Year Member



If you are working with .htaccess files, then you need to adjust the
^.*/((CRM)¦(82))/.*$
regular expression, because in the .htaccess files the path is stripped off, so the above pattern will not match. You will have to use
^((CRM)¦(82))/.*$
in that case.

If these texts (CRM and 82) is not both in the beginning of the path then you would need to use something like this:

^((CRM)¦(.+/82))/.*$
, or
^(.+/)?((CRM)¦(82))/.*$
.

The second rule is failing for more or less the same reason, the /CRM path does not contain the trailing slash, and there's no content after that, so you have to take this into account too.

So putting it all together, it comes to something like this:


# CRM & 82 should be a secure form. Redirect.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.+/)?((CRM)¦(82))(/.*)?$ [%{HTTP_HOST}%{REQUEST_URI}...] [R,L]


# If a member leaves the CRM or RA, make sure we're no longer in secure form. Redirect.
RewriteCond %{SERVER_PORT}
!^80$ 
RewriteRule
!^(.+/)?((CRM)¦(82))(/.*)?$ [%{HTTP_HOST}%{REQUEST_URI}...]  [R,L]