mod_rewrite and co-domain

Discussion in 'Tips/Tricks/Mods' started by SupuS, Jan 13, 2007.

  1. SupuS

    SupuS Member HowtoForge Supporter

    Hi all

    I created co-domains www.codomain.com and codomain.com under maindomain.com. I created subdirectory codomain_dir under maindomain's web direcotry with codomain content. But if I tried put to .htaccess this directive:

    Code:
    RewriteCond %{HTTP_HOST}  ^codomain.com
    RewriteRule (.*) codomain_dir/$1 [L,QSA]
    
    I supposed when I use URL codomain.com I get directly content of codomain_dir directory without codomain_dir name .. but id doesn't. I get error 500 only :(

    I searched on this forum and on apache docs for solutions but any of founded sugestions give me error 500 or do nothing ..

    Any ideas?

    Thanx a lot .. SupuS
     
    Last edited: Jan 13, 2007
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Please have a look at the error log of this domain and post the exact error that is logged there.
     
  3. SupuS

    SupuS Member HowtoForge Supporter

    Hi Till

    Thank you for hint .. with the error log file I found a solution .. and here it is..

    Code:
    # for adding www - not necessary
    RewriteCond %{HTTP_HOST}  ^subdomain.com
    RewriteRule (.*) http://www.subdomain.com/$1 [R=301,QSA,L]
    
    # main part .. for subdomain redirect
    RewriteCond %{HTTP_HOST}  ^[url]www.subdomain.com[/url]
    RewriteCond %{REQUEST_URI} !subdomain/
    RewriteRule (.*) subdomain/$1 [L,QSA]
    I hope this helps somebody .. :)

    SupuS
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    I moved the thread to the ttipps & tricks forum.
     
  5. Bicet

    Bicet Member

    My main domain is vagito.org

    I've created a codomain called webmail -> forwarding to folder webmail

    I've put this directive on the main page:

    Code:
    RewriteCond %{HTTP_HOST}  ^webmail.vagito.org
    RewriteCond %{REQUEST_URI} !webmail/
    RewriteRule (.*) webmail/$1 [L,QSA]
    
    But I get an error 400 bad request. Do you have any hint for my problem?
     
  6. SupuS

    SupuS Member HowtoForge Supporter

    Look at logs in www.vagito.org/log/error.log .. you can put directive to your httpd.conf for switching debug on .. may be it helps

    and remember .. with setting which you use webmail directory have to be directly under web directory ..
     
  7. Bicet

    Bicet Member

    my webmail is under web directory, I don't know why it doesn't work. And in error log I cannot find anything...
     
  8. falko

    falko Super Moderator Howtoforge Staff

    What's the output of
    Code:
    ls -la /path/to/webroot_directory
    ?
     
  9. Bicet

    Bicet Member

    I've tried again with another domain

    Here's what I've done so far:

    1. Create www.netsolutionsvenice.com (DNS Entry checked)
    2. Create co-domain webmail.netsolutionsvenice.com (on forward tab I've put webmail , without any slash)
    3. I've created the folder webmail inside /var/www/web8/web/
    4. Put that code on Apache directives:
    Code:
    RewriteCond %{HTTP_HOST}  ^webmail.netsolutionsvenice.com
    RewriteCond %{REQUEST_URI} !webmail/
    RewriteRule (.*) webmail/$1 [L,QSA]
    Here are the results:

    If you go to http://webmail.netsolutionsvenice.com you'll receive this one:

    And here are the ls -la of /var/www/web8
    Code:
    drwxr-xr-x  9 bicet_netsolutions web8 4096 2007-01-26 16:40 .
    drwxr-xr-x 12 root               root 4096 2007-01-26 16:13 ..
    drwxrwxr-x  2 bicet_netsolutions web8 4096 2007-01-25 14:29 cgi-bin
    -rw-------  1 bicet_netsolutions web8   24 2007-01-26 16:40 .forward
    -rw-rw-r--  1 root               web8   33 2007-01-26 04:00 .htpasswd
    drwxr-xr-x  3 bicet_netsolutions web8 4096 2007-01-26 00:30 log
    lrwxrwxrwx  1 root               root   45 2007-01-26 16:40 Maildir -> /var/www/web8/user/bicet_netsolutions/Maildir
    drwxrwxrwx  2 bicet_netsolutions web8 4096 2007-01-25 14:29 phptmp
    -rw-r--r--  1 root               root  507 2007-01-26 16:40 .procmailrc
    drwx------  2 bicet_netsolutions web8 4096 2007-01-25 14:33 .spamassassin
    drwxr-xr-x  2 bicet_netsolutions web8 4096 2007-01-25 14:29 ssl
    drwxr-xr-x  3 bicet_netsolutions web8 4096 2007-01-25 14:29 user
    lrwxrwxrwx  1 root               root   53 2007-01-26 16:40 .vacation.cache -> /var/www/web8/user/bicet_netsolutions/.vacation.cache
    drwxrwxr-x  5 bicet_netsolutions web8 4096 2007-01-26 16:33 web
    
    /var/www/web8/web
    Code:
    total 24
    drwxrwxr-x 5 bicet_netsolutions web8 4096 2007-01-26 16:33 .
    drwxr-xr-x 9 bicet_netsolutions web8 4096 2007-01-26 16:40 ..
    drwxrwxr-x 2 bicet_netsolutions web8 4096 2007-01-25 14:29 error
    -rw-rw-r-- 1 bicet_netsolutions web8 1220 2007-01-26 16:40 index.html
    drwxr-xr-x 2 bicet_netsolutions web8 4096 2007-01-26 04:00 stats
    drwxrwxr-x 2 bicet_netsolutions web8 4096 2007-01-26 16:34 webmail
    /var/www/web8/web/webmail
    Code:
    total 12
    drwxrwxr-x 2 bicet_netsolutions web8 4096 2007-01-26 16:34 .
    drwxrwxr-x 5 bicet_netsolutions web8 4096 2007-01-26 16:33 ..
    -rw-rw-r-- 1 bicet_netsolutions web8    7 2007-01-26 16:30 index.html
     
    Last edited: Jan 26, 2007
  10. Craig

    Craig New Member

    Just a quick note :
    Code:
    # for adding www - not necessary
    RewriteCond %{HTTP_HOST}  ^subdomain.com
    RewriteRule (.*) http://www.subdomain.com/$1 [R=301,QSA,L]
    
    Can cause problems due to the "/$1" which means it will add the slash whether it is needed or not. I find it works better simply as "http://www.subdomain.com$1"
     

Share This Page