Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2004
    Posts
    93

    htaccess rewrite with multiple domains

    I want to use htaccess rewrite so all http requests are directed to a directory in root:

    Code:
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.org$  [NC,OR]
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.net$  [NC,OR]
    RewriteCond %{HTTP_HOST} ^mydomain\.org$  [NC,OR]
    RewriteCond %{HTTP_HOST} ^mydomain\.net$  [NC]
    RewriteCond %{REQUEST_URI} !^/mydomain/.*$
    RewriteRule ^(.*)? /mydirectory/$1 [L]
    This is currently working.

    Can it be improved like this:

    Code:
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.(org|net)$  [NC]
    RewriteCond %{REQUEST_URI} !^/mydomain/.*$
    RewriteRule ^(.*)? /mydirectory/$1 [L]
    I'm unsure about how the round brackets (parentheses) are used.

    I want to catch www. or no www. with (www\.), and org or net with (org|net).

    Can I use round brackets to do this? Other options?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Posts
    93
    I've been testing that code... seems to be working...

  3. #3
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    More commonly you'd use something like this to allow you to serve any files that exist in the top level directory, but redirect other requests to the subdir:
    Code:
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.(org|net)$  [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/mydomain/.*$
    RewriteRule (.*) /mydirectory/$1 [L]
    (Note: if mydomain.org / .net is the only domain pointed to this account, you could leave the first line off altogether.)
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  4. #4
    Join Date
    Aug 2004
    Posts
    93
    Thanks for the reply.

    that's the thing--mydomain.org/net is NOT the only domain pointed to the account. this code let's me transparently host several sites on a single LAMP hosting account. As far as I know, there is no way a client can become aware of the other sites/domains hosted on the account.

  5. #5
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Do you allow scripting of any kind? (PHP / cgi / ssi)? If so, there are certainly ways a client could become aware of the other sites, and even alter them if he wanted to. You really should be using a reseller account to host clients.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  6. #6
    Join Date
    Aug 2004
    Posts
    93
    There are all kinds of scripts in /public_html/cgi-bin/. Each site stacked on the account has it's own directory in cgi-bin: /public_html/cgi-bin/mysite_1/ ; /public_html/cgi-bin/mysite_2/ and so on. But cgi-bin is password-protected. There is no way to access that directory, nor can those scripts be altered. What makes you think someone could become aware of, or alter other sites?
    Last edited by deko; 10-08-2009 at 11:26 AM.

  7. #7
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    By "allow scripting" I meant allowing the client to upload and run their own scripts. If you only allow them to run a selection of your scripts then your security (and that of all your clients) depends how well-written and secure those are - all the usual issues like sql injection, remote code inclusion, XSS, etc.

    Another consideration may be the host's ToS - most hosts don't permit you to resell their shared hosting accounts.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

Similar Threads

  1. htaccess / mod rewrite
    By abluegrape in forum Hosting Security and Technology
    Replies: 2
    Last Post: 06-19-2008, 02:39 AM
  2. url rewrite with .htaccess
    By chamelion in forum Hosting Security and Technology
    Replies: 5
    Last Post: 03-25-2008, 08:39 PM
  3. help with htaccess rewrite
    By kafloofen in forum Hosting Security and Technology
    Replies: 1
    Last Post: 01-17-2008, 12:54 PM
  4. htaccess and mod rewrite
    By Bambuk in forum Hosting Security and Technology
    Replies: 1
    Last Post: 11-05-2006, 01:58 PM
  5. rewrite using .htaccess
    By aawebtools in forum Dedicated Server
    Replies: 2
    Last Post: 05-22-2001, 08:40 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
  •