Results 1 to 4 of 4
  1. #1
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    551
    .htaccess, http: 2 https: and the other way around
    I want to force the use of http or https using .htaccess and at the same time I want to force the use of www

    so for example,

    if I was going to http://mydomain.com/secure/ the url would be forced to https://www.mydomain.com/secure/

    or if I was going to https://mydomain.com/ the url would be forced to http://www.mydomain.com/

    and of course whatever came behind it as well, like myscript.php?life=45&wife=1

    I have been through quite a few variations on a theme but never come up with the right solution.

    Anyone know how to do this?

  2. #2
    Affiliate Manager dgreen's Avatar
    Join Date
    October 31st, 2005
    Posts
    14
    There is a great article on this information here.

    http://www.yourhtmlsource.com/sitema...rewriting.html

  3. #3
    pph Expert! Gordon's Avatar
    Join Date
    January 18th, 2005
    Location
    Edmonton Canada
    Posts
    5,781
    Hi Wayder,

    I dont know about the http, https bit but this is what I am using to ensure the WWW bit is always included.

    I am using this format on my .htaccess on quite a few of my sites and it seems to work ok for me. Just replace domainname with whatever.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domainname\.com
    RewriteRule (.*) http://www.domainname.com/$1 [R=301,L]
    One day parasites and their ilk will be made illegal, I bet a few Lawyers will be pissed off when the day comes.
    Mr. Spitzer is fetching it nearer

    YouTrek

  4. #4
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    551
    I think I found it. This is what seems to be working for me at the moment.

    root .htaccess

    ErrorDocument 404 http://www.mydomain.com/error.php
    Options All -Indexes
    RewriteEngine on

    RewriteCond %{HTTP_HOST} \.
    RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
    RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

    RewriteCond %{SERVER_PORT} !^80$
    RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

    directory secure .htaccess

    ErrorDocument 404 https://www.mydomain.com/secure/error.php
    Options All -Indexes
    RewriteEngine on

    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule (.*) https://www.mydomain.com/secure/$1 [R=301,L]

    RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
    RewriteRule (.*) https://www.mydomain.com/secure/$1 [R=301,L]

    To date with my testing it works on all subdirectories correctly.

    I tried placing SERVER_PORT within the first set of rewrite conditions but it didnt work. I dont know why as yet. If anyone has any opinions about that.

    I did get a flash of the invalid certificate at one point but it dissapeared very quickly. I think this is because I redirected in the wrong order.

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Question regarding https & forms
    By dMahoney in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: March 22nd, 2011, 11:07 PM
  2. http header says: HTTP/1.1 302 Object moved
    By Roland in forum Midnight Cafe'
    Replies: 2
    Last Post: August 25th, 2005, 09:11 AM
  3. CJ login problems - http and https
    By Ivan22222 in forum Commission Junction - CJ
    Replies: 2
    Last Post: August 15th, 2005, 04:33 AM
  4. https://vhost.oddcast.com
    By jc101 in forum Virtual Family and Off-Topic
    Replies: 7
    Last Post: January 7th, 2003, 04:40 PM
  5. CJ.com - Secure (https) web site
    By Affiliate in forum Commission Junction - CJ
    Replies: 0
    Last Post: December 13th, 2002, 04:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •