Forum Moderators: phranque

Message Too Old, No Replies

Wildcard DNS .Htaccess

htaccess and wildcard DNS to make subdomain use subfolders silently

         

i2k2

4:44 am on Dec 29, 2007 (gmt 0)

10+ Year Member



Continueing from [webmasterworld.com...]

I Have wildcard DNS enabled on my server and i am using the following htaccess rules
RewriteEngine On
RewriteCond %{HTTP_HOST}__SPACE__!^$
RewriteCond %{HTTP_HOST}__SPACE__!^(www\.)?mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC]
RewriteCond %2<->%3__SPACE__!^(.*)<->\1$ [NC]
RewriteRule ^(.+) /%2/$1 [L]

Now the problems is really strange.The site had many pre existing subdomains. but after using the above htaccess rules some sub domains started to work while others did not work.They started giving ERROR 500.i don't know why?
the sub domains which worked are of blogs.subdomain.com
and forums.subdomain.com
and all other subdomains did not work.even if i create new sub domains from my cpanel console, the new subdomain do not work and they start giving error 500.

Moreover sub domains are not using contents of the respective folders.

jdMorgan

4:50 am on Dec 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two questions:

You have replaced _SPACE_ with a literal space character, right?
And you have verified with your host that your server supports POSIX 1003.2 regular expressions or later? Not all server OSes support these regular expressions, and if yours does not, then this code won't ever work on it.

Jim

jdMorgan

4:58 am on Dec 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I should also add that this code is not meant to be used with subdomains which are set up using a control panel. It is meant to be used with a hand-edited httpd.conf file that points all subdomains to the "main" domain's root directory. It could be used with a control panel if the control panel supports this function.

This is the likely cause of your "some subdomains work, some don't" problem. You will either need to use the same subdomain-to-subdirectory mapping method that your control panel used when setting up "blog" and "forum" or you will need to add exceptions to httpd.conf and/or .htaccess so that the configuration code sections don't interfere with each other.

So much depends on exactly what code your control panel "wrote" in httpd.conf to define the subdomains that I wouldn't even care to guess at the details of what you'll need to do. You might want to try to get *one* additional subdomain working first (in addition to "blogs" and "forums") and then take the next step to a full "wild-card" setup.

Jim

i2k2

6:54 am on Dec 29, 2007 (gmt 0)

10+ Year Member



Thanks for the reply.
first of all i would like to point out that i have removed all the spaces fro m the htaccess code.

if i do not use the above htaccess rules then all the subdomains point to the root directory,this means that wildcard dns has been installed correctly.

once i use those codes all the subdomains shows me error 500 except blogs and forums sub domain.I tried checking access logs and error logs but to no avail.
In the meantime,i emailed host to show me what they have done in httpd.conf. once i get that info i will post here too.

i2k2

8:40 am on Dec 29, 2007 (gmt 0)

10+ Year Member



here is the entry done by webhost in httpd.conf

please have a look
================================================
NameVirtualHost ip.ip.ip.ip:80

ServerAlias www.mydomain.com *.mydomain.com => Entry for wildcard dns
ServerAdmin webmaster@mydomain.com
DocumentRoot /home/cpanelusername/public_html

UserDir disabled
UserDir enabled cpanelusername

ServerName mydomain.com

suPHP_UserGroup cpanelusername cpanelusername

User cpanelusername
Group cpanelusername

BytesLog /usr/local/apache/domlogs/mydomain.com-bytes_log
CustomLog /usr/local/apache/domlogs/mydomain.com combined
ScriptAlias /cgi-bin/ /home/cpanelusername/public_html/cgi-bin/

=========================================================

jdMorgan

7:37 pm on Dec 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two questions:
...
And you have verified with your host that your server supports POSIX 1003.2 regular expressions or later? Not all server OSes support these regular expressions, and if yours does not, then this code won't ever work on it.

i2k2

1:44 am on Dec 30, 2007 (gmt 0)

10+ Year Member



they say that they have installled posix for my server.

i2k2

3:13 am on Dec 30, 2007 (gmt 0)

10+ Year Member



hey jdMorgan,
I did not figure out what the problem was but i found a solution to the problem.
the subdomains blogs.mydomain.com and forums.mydomain.com worked because they had an .htaccess file in their root directory.
so i put a .htaccess file with following entry in rest of the folders and subdomains and they worked like charm.
==========================================
# Turn RewriteEngine on
RewriteEngine On
#
===========================================
Rest of subdomains were giving Error 500 because they did not have any .htaccess file in the folder.
Thanks everybody here.