Help with Apache2, virtual subdomains and rewrite rules

Using a single web hosting account to host multiple sites

Help with Apache2, virtual subdomains and rewrite rules

Postby humaneasy » Sun Aug 13, 2006 4:29 am

Hi,

It must be something wrong somewhere because some of the rules do not work as they should.

I only replaced the domain part using domain.tld because this is a public forum.

My Apache information as taken from phpinfo() is
Code: Select all
apache2handler
Apache Version    Apache/2.0.54 (Fedora)
Apache API Version    20020903
Server Administrator    root@localhost
Hostname:Port    www.domain.tld:0
User/Group    apache(48)/48
Max Requests    Per Child: 1000 - Keep Alive: off - Max Per Connection: 100
Timeouts    Connection: 120 - Keep-Alive: 15
Virtual Server    Yes
Server Root    /etc/httpd
Loaded Modules    core prefork http_core mod_so mod_access mod_auth mod_auth_anon mod_auth_dbm mod_auth_digest util_ldap mod_auth_ldap mod_include mod_log_config mod_logio mod_env mod_mime_magic mod_cern_meta mod_expires mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime mod_dav mod_status mod_autoindex mod_asis mod_info mod_dav_fs mod_vhost_alias mod_negotiation mod_dir mod_actions mod_speling mod_userdir mod_alias mod_rewrite mod_proxy proxy_ftp proxy_http proxy_connect mod_cache mod_suexec mod_disk_cache mod_file_cache mod_mem_cache mod_cgi mod_evasive20 mod_perl mod_php5 mod_python mod_ssl

Directive   Local Value   Master Value
engine   1   1
last_modified   0   0
xbithack   0   0


This is the .htaccess that is there:
Code: Select all
    Options +FollowSymLinks

    RewriteEngine On

    # Strip www. (Doesn't work if uri is /cgi-bin or /icons.)
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule .* http://%1/$1 [R=301,L]

    # mod_dir fix.
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain.tld$ [NC]
    RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI}/ -d
    RewriteRule !/$ %{REQUEST_URI}/ [R=301,L]

    # If directory exists for subdomain, rewrite it.
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain.tld$ [NC]
    RewriteCond %{DOCUMENT_ROOT}/%1/ -d
    RewriteCond %1%{REQUEST_URI} !^([^\.]+)/\1(/.*)?$
    RewriteRule ^(.*)$ /%1/$1 [QSA,L]

    # Directory doesn't exist for subdomain.
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain.tld$ [NC]
    RewriteCond %{DOCUMENT_ROOT}/%1/ !-d
    RewriteRule .* http://www.a-diferent-domain.tld/ [R=301,L]

    # /subdomain/ --> subdomain.domain.tld
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_URI} ^/([^/]+)(/.*)?$
    RewriteCond %{DOCUMENT_ROOT}/%1/ -d
    RewriteRule .* http://%1.domain.tld%2 [R=301,L]

The .htaccess doesn't work, except the rule that redirects to the magazine.

Tried with:
  1. www.domain.tld and domain.tld -> redirects to the a-diferent-domain.tld as it should
  2. www.domain.tld/subdomain/ -> redirects as #1 even if the dir exists and it should rewrite to subdomain.domain.tld/
  3. domain.tld/subdomain/ -> redirects as #1 but to /subdomain/ even if the dir exists and it should rewrite to subdomain.domain.tld/
  4. http://subdomain.domain.tld/ -> returns page load error, address not found
  5. http://www.subdomain.domain.tld/ -> returns page load error, address not found
I think those were all the options and the results were strange as they can be :)
This is the current .httpd.conf section related with my domain
Code: Select all
<VirtualHost *:80>
    DocumentRoot /home/lopo/data/htdocs
    ServerAlias *.domain.tld
    ServerName www.domain.tld
    CustomLog /home/lopo/logs/access_log common
    ScriptAlias /cgi-bin/ /home/lopo/data/cgi-bin/
    #RedirectMatch 301 (.*) http://domain.tld$1

    <Directory /home/lopo/data/htdocs>
    AllowOverride All
    </Directory>

</VirtualHost>

Help please.
humaneasy
 
Posts: 14
Joined: Sat Jul 08, 2006 4:37 pm

Postby richardk » Sat Aug 19, 2006 2:30 pm

richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 59 guests

cron