The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Shared SSL and mod_rewrite

Discussion in 'General Discussion' started by peterr, Sep 27, 2003.

  1. peterr

    peterr Well-Known Member

    Joined:
    Sep 24, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    I'm a reseller who has purchased a Comodo SSL, that I can use for my domain, or use, on a shared basis, for any users (accounts as a reseller).

    I don't have access to httpd.conf or anything like that, and would like to use .htaccess and mod_rewrite. The objective is to:

    https://secure.example.com/domainname/order-form.php
    to be internally redirected to
    https://secure.example.com/~username/order-form.php

    where example.com is my domain, and domainname is the domain where the file order-form.php resides. (the users domain). Here is what I have been using:

    /home/example/public_html/.htaccess

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    # Check that it's 443 port
    RewriteCond %{SERVER_PORT} ^443$
    # Make proxy redirection
    RewriteRule ^secure/domainname/order-form\.php$   [url]https://secure.example.com/~username/order-form.php[/url] [P]
    When I test this, using https://secure.example.com/domainname/order-form.php, I get a "404".

    I ran some more tests, using the results of phpinfo, to see what path the URI's evaluated to:

    https://secure.example.com ----> /home/example/public_html
    https://secure.example.com/secure ----> /home/example/public_html/secure
    https://example.com/secure ----> error message
    http://secure.example.com ----> /home/example/public_html/secure
    http://secure.example.com/secure ----> 404
    http://example.com/secure ----> /home/example/public_html/secure

    The error message was "The connection to example.com was terminated unexpectedly. Some data may have been transferred".

    You can see that the HTTPS connection is going to different paths, when compared to the HTTP connection. :)

    I have tested that .htaccess parsing is enabled and that mod_rewrite is installed by creating a new subdirectory, adding a .htaccess with:

    Code:
    RewriteEngine On
    Then, browsed the page www.example.com/subdirectory/ , and there were no errors.

    Does anyone have any ideas why the "RewriteRule" in mod_rewite is not working ?

    Thanks,

    Peter

    cPanel.net Support Ticket Number:
     
    #1 peterr, Sep 27, 2003
    Last edited: Sep 27, 2003
  2. peterr

    peterr Well-Known Member

    Joined:
    Sep 24, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    The .htaccess on my domain (example.com), now has the following entries:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    # rewrite base to make sure it is in the public_html path
    RewriteBase /
    # Check that it's 443 port
    RewriteCond %{SERVER_PORT} ^443$
    # Make proxy redirection
    RewriteRule ^domainname/order-form\.php$ /~username/order-form.php
    
    ... and it works just fine; the ~username is completely hidden (and secure).

    Peter

    cPanel.net Support Ticket Number:
     
  3. jcn

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
    Oh that's really cool peterr.

    Just to confirm, I assume that you have to write in a separate Rewrite rule for each domain name manually, right?

    cPanel.net Support Ticket Number:
     
  4. peterr

    peterr Well-Known Member

    Joined:
    Sep 24, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    Yes, I can't see an (easy) way, other than specifically writing the rule so that a domainname matchs a username. This way, you can control who uses your (shared) SSL, and be sure that it points to the right 'username' (which is a domain).

    Peter

    cPanel.net Support Ticket Number:
     
  5. jcn

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
    For things like this I've been writing little scripts that get tacked onto the end of /scripts/postwwwacct that do things like modify the new domain's dns record to change the MX and add a custom preference file to a custom squirrelmail install that I have.

    It should be easy enough to go in and add a Rewrite line to the .htaccess file for the secure subdomain.

    cPanel.net Support Ticket Number:
     
  6. mjm

    mjm BANNED

    Joined:
    Aug 1, 2003
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    6
    what is the point of this? the user is still on example.com not their own domain.....

    i know it looks better without the tilda, but still.....

    cPanel.net Support Ticket Number:
     
  7. jcn

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
  8. peterr

    peterr Well-Known Member

    Joined:
    Sep 24, 2003
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    By removing (hiding) the tilde character, it provides much better security for the domain, because the username that appears after the tilde character is the login name. As webmaster for the site, I'd prefer it if the general public don't know the login name to the account.

    By the use of "mod_rewrite" and a lot of help from an Apache guru, it is all working perfectly now. The user can go through my shared SSL connection, with their own domain name shown. All other URL's within the form are using a secure connection. It is only about 5 lines in .htaccess.

    Regards,

    Peter

    cPanel.net Support Ticket Number:
     
Loading...

Share This Page