Forum Moderators: phranque

Message Too Old, No Replies

What's wrong in my code?

I want few pages of my site to be in https

         

zaira_86

9:24 pm on Mar 19, 2010 (gmt 0)

10+ Year Member



Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule ^(.*)$ [mysite.com...] [R=301,L]
#Redirect the pages below to html and it must be in SSL
RewriteCond %{HTTPS} =on
RewriteRule ^contactus\.html$ contactus.php
RewriteRule ^login\.html$ user_login.php
RewriteRule ^registration\.html$ user-registration.php
RewriteRule ^logout\.html$ logout.php

#Redirect the pages below to https if requested via http
RewriteCond %{HTTPS} !=on
RewriteRule ^contactus\.html$ [mysite.com...] [NC,R=301,L]
RewriteRule ^login\.html$ [mysite.com...] [NC,R=301,L]
RewriteRule ^registration\.html$ [mysite.com...] [NC,R=301,L]
RewriteRule ^logout\.html$ [mysite.com...] [NC,R=301,L]
RewriteRule ^site-tradeshow\.html$ tradeshow.php
RewriteRule ^site-aboutus\.html$ tradeshow.php

# Redirect non-canonical hostname requests to canonical domain
RewriteCond %{HTTP_HOST} !=www.mysite.com
RewriteCond %{HTTPS}>s ^(on>(s)|[^>]+>s)$
RewriteRule ^(.*)$ http%2://www.mysite.com/$1 [R=301,L]

Sorry, im really new to htaccess I can't figure why this code isn't working. Basically, I want contactus, login, registration, logout pages to be in https. If the url is requested via http make it https.

Then tradeshow and aboutus should not be in https. If its requested via https: make it http. Why is my code isn't working? Any idea, please?

g1smd

11:13 pm on Mar 19, 2010 (gmt 0)

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



Every rule should have an [L] flag.


Options -Indexes
Options +FollowSymlinks

Change to:

Options -Indexes +FollowSymlinks


RewriteBase /

This is the default and is not required.

#Redirect the pages below to html and it must be in SSL

Those lines do NOT do that. They are rewrites. A redirect would include protocol and domain name as well as the [R=301,L] flag.

RewriteCond %{HTTP_HOST} ^mysite\.com [NC]

Change to:

RewriteCond %{HTTP_HOST} !^(www\.mysite\.com)?$


This non-www to www redirect should be after the other redirects.

$1 is undefined in many of your redirects. Are the final two of those supposed to be a redirect or a rewrite? As coded, they are rewrites and the [L] flag is missing. If they are supposed to be rewrites, two URLs serve identical content. If they are supposed to be redirects add the protocol and domain name and the [R=301,L] flags.


In this post, the words 'redirect' and 'rewrite' have very specific meanings.

zaira_86

3:40 am on Mar 20, 2010 (gmt 0)

10+ Year Member



Ok , i want my
contactuspage.php to be rewrited into contact.html
user_login.php to be rewrited into login.html
user-registration to be rewrited into registration.html
logout.php to be rewrited into logout.html
tradeshow.php to be rewrited into site-tradeshow.html
aboutus.php to be rewrited into site-aboutus.html

Then, i want my contact, login, registration, and logout.html to be open in HTTPS. Example url would look like this [example.com...] If it's open as http://www.example.com/contact.html the url should automatically be change into [example.com...]

Any idea on how to code this?

[edited by: jdMorgan at 10:15 pm (utc) on Mar 20, 2010]
[edit reason] example.com [/edit]

jdMorgan

10:20 pm on Mar 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This thread will be more productive and your problems will be solved faster if you will do three things:
1) Tell us exactly what you mean by "It does not work." This phrase is essentially meaningless without a *lot* more information about how you tested, the results you got, and how those results differed from your expectations.
2) Do not try to write and debug the whole file with all functions all at once. Rather, decide which single problem you want to solve first, test your code, report the results as requested above, and ask specific questions about that one problem. Having solved that problem, move on to the next one.
3) Realize that we are here to help you with *your* code and *your* problem. We cannot write your code and test it for you without offering the same "service" to the rest of the world. Obviously, that is not possible in a small forum such as this.

Thanks,
Jim