apache2 RewriteCond questions

Discussion in 'Installation/Configuration' started by MisterVlad, Jan 23, 2009.

  1. MisterVlad

    MisterVlad New Member

    Ok... what i am looking for, is to setup squirrelmail a little easier/better.

    I have a bunch of domains on my server, all of them are working fine right now. but they all have to goto http://www.theirdomainname.com/squirrlemail

    what i would LOVE to have happen, is the point http://webmail.theirdomainname.com or http://mail.theirdomainname.com goto the squirrelmail login page.

    What i would like not to happen (it is a personal thing) is just have that URL at the top, and it JUST show http://webmail (or mail).theirdomainname.com without anything after. currently the /squirrelmail redirects and puts /squirrelmail/src/login.php in the address bar.


    Is this easy to do on a global basis? or am I going to have to add that to every domain that i host?

    thanks :)
     
  2. Miguel

    Miguel New Member HowtoForge Supporter

    Rewrite condition

    MisterVlad,

    this should do the trick. I use to have gallery.mydomain.tld rather than mydomain.tld/gallery

    RewriteEngine On
    RewriteBase /
    # Rewrite foo subdomain requests to foo subdirectory
    RewriteCond %{HTTP_HOST} ^squirrel\.yourdomain\.tld
    RewriteCond %{REQUEST_URI} !^/squirrel/
    RewriteRule (.*) /squirrel/$1 [L]
    Put this in the .htaccess in the root of yourdomain.tld.

    Please note that the above works with the directory name. So if squirrelmail is installed in squirrel or squirrelmail you will need to use squirrel respectively squirrelmail. Renaming the directory to webmail or mail does the trick.

    The is also a rule to redirect requests for yourdomain.tld/squirrel to squirrel.yourdomain.tld but I can't find for the moment.

    Have fun.
     
  3. MisterVlad

    MisterVlad New Member

    ok, you say to put that in teh .htaccess in my root domain, but...

    what if someone goes to webmail.domain2.com, does it have to be in there as well??

    what i need, is:
    webmail.domain1.com
    webmail.domain2.com
    webmail.domain3.com
    and/or
    domain1.com/webmail
    domain2.com/webmail
    domain3.com/webmail

    all to point to the webmail... but i would like to have it read in the addressbar as webmail.{whicheverdomainnametheyareon}.com/

    does that make sense on what i am askign?
     
  4. Miguel

    Miguel New Member HowtoForge Supporter

    Domain .htaccess

    You need to put this in each domain's .htaccess to work.

    So you need it i domain1.tld, domain2.tld, ...

    The syntax of the rewrite condition is specific for each domain:

    RewriteCond %{HTTP_HOST} ^mail\.domain1\.tld

    RewriteCond %{HTTP_HOST} ^squirrel\.domain2\.tld

    ...
     
  5. Miguel

    Miguel New Member HowtoForge Supporter

    More specific:

    In domain1 .htaccess

    RewriteEngine On
    RewriteBase /
    # Rewrite foo subdomain requests to foo subdirectory
    RewriteCond %{HTTP_HOST} ^squirrel\.domain1\.tld
    RewriteCond %{REQUEST_URI} !^/squirrel/
    RewriteRule (.*) /squirrel/$1 [L]

    In domain2 .htaccess

    RewriteEngine On
    RewriteBase /
    # Rewrite foo subdomain requests to foo subdirectory
    RewriteCond %{HTTP_HOST} ^squirrel\.domain2\.tld
    RewriteCond %{REQUEST_URI} !^/squirrel/
    RewriteRule (.*) /squirrel/$1 [L]
     
  6. MisterVlad

    MisterVlad New Member

    There's no way around it? that's the only way is to put it in everyone's .htaccess?


    I thought that there would be a way to do this within the apache .conf files (or sites-enabled)?
     
  7. Miguel

    Miguel New Member HowtoForge Supporter

    You could try putting it in rewrite.conf, but I never did.

    To do so you need to disable rewrite and re-enable rewrite to enable the .conf file.

    First of course write the .conf file. For ubuntu/debian it should be in /etc/apache2/mods-available/rewrite.conf

    RewriteEngine On
    RewriteBase /
    # Rewrite foo subdomain requests to foo subdirectory
    RewriteCond %{HTTP_HOST} ^squirrel\.domain1\.tld
    RewriteCond %{HTTP_HOST} ^squirrel\.domain2\.tld
    RewriteCond %{HTTP_HOST} ^squirrel\.domain3\.tld
    RewriteCond %{REQUEST_URI} !^/squirrel/
    RewriteRule (.*) /squirrel/$1 [L]

    Given that the subdirectory has the same name for all domains this might work.

    You can of course put it in the apache vhost conf of each domain. Than you don't need to put it in the .htaccess, but in each apache vhost configuration.

    My best bet is to still put it in the root folder of each site to make it work.
     

Share This Page