Re: Apache2 & mod_rewrite

From: Simo Kauppi (swk_at_nic.fi)
Date: 09/12/05

  • Next message: Joe Smith: "Re: reinstall lilo after windows"
    Date: Mon, 12 Sep 2005 01:04:05 +0300
    To: debian-user@lists.debian.org
    
    
    

    On Sun, Sep 11, 2005 at 09:38:37PM +0200, Marco wrote:
    > Hi,
    > I have a problem with apache2 and rewrite module.
    >
    > VirtualHost for site www.domain1.com
    > ...
    > RewriteCond %{HTTP_HOST} !^www\.domain1\.com [NC]
    > RewriteCond %{HTTP_HOST} !^$
    > RewriteRule ^/(.*) http://www.domain1.com/$1 [L,R]
    >
    > TEST OK. http://domain1.com --> http://www.domain1.com
    >
    > When I make the virtual host for site www.domain2.com
    > I have problems.
    >
    > VirtualHost for site www.domain2.com
    > ...
    > RewriteCond %{HTTP_HOST} !^www\.domain2\.com [NC]
    > RewriteCond %{HTTP_HOST} !^$
    > RewriteRule ^/(.*) http://www.domain2.com/$1 [L,R]
    >
    > TEST PROBLEM: http://domain2.com --> http://www.domain1.com
    >
    > Could you help me?
    > Thanks
    >
    > Marco

    It seems to me that the conditions for the first domain say that
    any hostname which is not www.doamin1.com should go to www.domain1.com.
    I.e. Apache is doing exacly as asked (domain2.com != www.domain1.com) :)

    I guess you want requests to http://domain2.com to go to the second
    virtual host and www added at the front? IIRC Apache looks for the
    virtual host files in /etc/Apache2/sites-enabled/ directory in the order
    their appear. That's why I use the 001-site1, 002-site2 etc to make them
    appear alphabetically in the right order.

    But back to your question. You need a condition to tell domain1 that it
    only takes requests for domain1, i.e.,

    > VirtualHost for site www.domain1.com
    > ...
      RewriteCond %{HTTP_HOST} ^.*domain1\.com [NC]
    > RewriteCond %{HTTP_HOST} !^www\.domain1\.com [NC]
    > RewriteCond %{HTTP_HOST} !^$
    > RewriteRule ^/(.*) http://www.domain1.com/$1 [L,R]

    or something like that, and same for other hosts as well. It's late so
    double-check the syntax :)

    And don't forget http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

    Hope this helps...

    Simo

    -- 
    :r ~/.signature
    
    

    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    


  • Next message: Joe Smith: "Re: reinstall lilo after windows"

    Relevant Pages

    • Re: secured virtual host
      ... That's not a name-based virtual host. ... host as your apache2 and, or the hardware can accommodate or serve. ... You need to create respective certificate and, ... Linux 2.6.20.7 x86_64 GNU/Linux Registered Linux user #261729 ...
      (comp.os.linux.misc)
    • Apache2 error 403
      ... I have just converted over to Apache2 when installing SuSE Linux and ... when I try to access the web page of a virtual host, ... permissions, owner, and group to that os /srv/www/htdocs but to no avail. ...
      (alt.os.linux.suse)
    • Re: Logfile for vhosts (mod_rewrite)
      ... 'i' instead of 'e' in the customlog directive ... ... So apparently in the requests for the images from the webpage there is no ... apache knows from which virtual host ... : RewriteCond %!^$ ...
      (comp.os.linux.setup)
    • Re: problems with apache2 and virtual hosting
      ... All requests are being handled by the default ... > virtual host, which is obviously not what I want. ... I trust, you have restarted apache2 after the changes:) ...
      (Debian-User)
    • problems with apache2 and virtual hosting
      ... All requests are being handled by the default ... virtual host, which is obviously not what I want. ... What could be causing it to fail ... Re-Interpreting Historic Miracles with SED #141: ...
      (Debian-User)