SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    595
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Three domains, same website and mod_rewrite

    Hi,

    We have three domains, all on the same website (same server), and need to use mod_rewrite so that when a user has this in the (address) browser bar:

    http://example1.com

    the mod_rewrite will actually let the user see the contents of

    http://example1.com/shop1

    This needs to happen for the 3 domains (which are actually seperate 'stores' or 'shops', but share the same database - osCommerce). Therefore, if any user has the following in the browser bar, the mod_rewrite will do this:

    http://example1.com ---mod_rewrite--> http://example1.com/shop1
    http://example2.com ---mod_rewrite--> http://example1.com/shop2
    http://example3.com ---mod_rewrite--> http://example1.com/shop3

    We would not want the browser bar URL to change, in fact the default file is 'index.php', so when they visit:

    http://example1.com/index.php

    they will _really_ be at:

    http://example1.com/shop1/index.php

    Hope that makes sense.

    There is another minor matter, and I assume it is best dealt with by "mod_rewrite". We only want people to visit the site, using any of the 3 domain names. They could, if they knew some other details, get to the site like this:

    http://IP.add.re.ss/~username

    OR

    http://webserver_name/~username

    because we have PHP code to check for domain name only, if anyone attempts access like that described above, we would like a "404" page displayed, or similar, informing them of the error.

    Thanks,

    Peter

  2. #2
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    595
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Therefore, if any user has the following in the browser bar, the mod_rewrite will do this:

    http://example1.com ---mod_rewrite--> http://example1.com/shop1
    http://example2.com ---mod_rewrite--> http://example1.com/shop2
    http://example3.com ---mod_rewrite--> http://example1.com/shop3
    Would the following in /.htaccess be the solution ??

    Code:
    RewriteEngine on
    RewriteCond   %{REMOTE_HOST}  !^.+\.example1\.com$
    RewriteRule   ^(/~.+)         http://example1.com/shop1/$1 [R,L]
    Thanks,

    Peter

  3. #3
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry Peter for the delay but I'm really busy these weeks.
    You need to use this rules:

    /.htaccess
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
    RewriteRule !^shop1/.*$ /shop1%{REQUEST_URI} [NC,L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com$ [NC]
    RewriteRule !^shop2/.*$ /shop2%{REQUEST_URI} [NC,L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example3\.com$ [NC]
    RewriteRule !^shop3/.*$ /shop3%{REQUEST_URI} [NC,L]
    Story Juice:
    www.example1.com would go under www.example1.com/shop1/
    www.example1.com/pippo.gif would go under www.example1.com/shop1/pippo.gif
    www.example1.com/path/to/pippo.php would go under www.example1.com/shop1/path/to/pippo.php

    Same Juice for example1, and exampl2.

    Is it what you were looking for ?
    Let me know.
    After that is okay we will take a look at your other questions .


    Thanks,
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  4. #4
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    595
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pippo,

    Sorry to hear you are so busy, ..... hope you take it easy, and can take a break soon.

    Quote Originally Posted by pippo
    You need to use this rules:

    /.htaccess
    Code:
     Options +FollowSymLinks
     RewriteEngine On
     
     RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
     RewriteRule !^shop1/.*$ /shop1%{REQUEST_URI} [NC,L]
     
     RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com$ [NC]
     RewriteRule !^shop2/.*$ /shop2%{REQUEST_URI} [NC,L]
     
     RewriteCond %{HTTP_HOST} ^(www\.)?example3\.com$ [NC]
     RewriteRule !^shop3/.*$ /shop3%{REQUEST_URI} [NC,L]
    Story Juice:
    www.example1.com would go under www.example1.com/shop1/
    www.example1.com/pippo.gif would go under www.example1.com/shop1/pippo.gif
    www.example1.com/path/to/pippo.php would go under www.example1.com/shop1/path/to/pippo.php

    Same Juice for example1, and exampl2.

    Is it what you were looking for ?
    Yes, that is exactly what I'm looking for. I forgot to mention that the domains are "COM.AU", so would the rewrite conditions be of this format then ?

    Code:
      RewriteCond %{HTTP_HOST} ^(www\.)?example1\com\.au$ [NC]
    OR ..........

    Code:
       RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com\.au$ [NC]
    We do already have some mod_rewite's in the .htaccess (compliments of 'pippo' ), as follows:

    .htaccess

    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 ^someotherdomain.com.au/order-form\.php$ /~username/order-form.php
     # rule for all GIF files
     RewriteRule ^someotherdomain.com.au/images/([^.]+\.gif)$ /~username/images/$1
    but the domain called "someotherdomain.com.au" is not one of the domains mentioned in the three shop example, where we used:

    example1.com.au
    example2.com.au
    example3.com.au

    ... just thought I should mention that there is already a rewrite condtion and rule, but it is definitely for another domain, to handle a shared HTTPS connection. I just needed to be sure that there would be no conflicts. The way I'm trying to understand mod_rewrite "conditions" and "rules", is that if the condition is true, all the following rules will apply, until another condition command ( RewriteCond) is evaluated. They act like a 'set' I guess.

    Btw, I don't remember putting this in .htaccess, maybe CPanel did it ? Can you please explain what this code does.

    Code:
     <Files 403.shtml>
     order allow,deny
     allow from all
     </Files>
    I don't have a file called '403.shtml' in the /public_html path, and a 403 is "forbidden" I think, from memory ??

    Thanks for all your help,

    Peter

  5. #5
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a)
    > RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com\.au$ [NC]
    THat's correct.
    \. means ``dot''
    The dot had to be escaped, by adding the ``\'', because regular expressions will consider ``.'' as ``every character''.

    Some examples:
    example1\.com\.au
    will only match example1.com.au

    example1.com.au
    will match
    example1.com.au
    example1Acom.au
    example1.comBau
    example1AcomBau
    example1.comUau
    example1.comZau
    so on...

    b)
    Yes, the old rules should not be in conflict with the new ones...
    > The way I'm trying to understand mod_rewrite "conditions" and "rules",
    > is that if the condition is true, all the following rules will apply, until another
    > condition command ( RewriteCond) is evaluated. They act like a 'set' I guess.
    An example should make it clear:

    RewriteCond something george
    RewriteRule do_something

    RewriteCond something_other strait
    RewriteRule do_something_other

    is like to write:
    if (something == george) {
    do_something();
    }

    if (something_other == strait) {
    do_something_other();
    }

    c)
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>



    But in pratice it says:
    A 403.shtml can be accessed

    So if in some directory you have denied all accesses doing the previous staff you can access all 403.shtml from there.

    I have to say that I don't know CPanel, never used a control panel in my life...I'm an old-text-coder guys...lol


    Hope It Really Helped
    Andrea
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  6. #6
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    595
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pippo,

    Quote Originally Posted by pippo
    Code:
    RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com\.au$ [NC]
    Thanks for confirming that one, and for explaining about regular expressions,etc.

    Quote Originally Posted by pippo
    Yes, the old rules should not be in conflict with the new ones...
    Great news, and I understand now that the mod_rewite 'Cond/Rule' are just like an "IF" construct, thanks.

    Quote Originally Posted by jehoshua
    Code:
     <Files 403.shtml>
     order allow,deny
     allow from all
     </Files>
    Quote Originally Posted by pippo
    But in pratice it says:
    A 403.shtml can be accessed

    So if in some directory you have denied all accesses doing the previous staff you can access all 403.shtml from there.
    Okay, so it is just a method to have one "403" file, to be used (displayed) when a 'forbidden' happens in any directory. It must have been put there by CPanel, I don't remember putting it there.

    Quote Originally Posted by pippo
    I have to say that I don't know CPanel, never used a control panel in my life...I'm an old-text-coder guys...lol
    Well, CPanel is nice I guess, but I understand that working at shell level will give you a much better understanding of the OS and many other things.

    Thanks for all your help, you are a good tutor.

    Peter


Bookmarks

Posting Permissions

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