Monday, December 26, 2005

catchall (catch-all) subdomains using cpanel and htaccess

I have looked around on how to do this but no one seems to know how to do IT. I hope by starting this thread I will get to a solution and help other people searching, as it is a common issue.
This is the background and what I have done till now.

So, I have cpanel access from my provider, also I am a reseller and have whm access.
until now, I found a way to convert : http://www.google.com/url?sa=D&q=http://example1.mydomain.com to http://www.google.com/url?sa=D&q=http://www.mydomain.com/example1
this can be done easily using the .htaccess file on the root of your file structure: So just edit or create the file .htaccess and make sure it contains those lines :
RewriteEngine On RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.google.com/url?sa=D&q=http://mydomain.com/%251 [L,R]

replace "mydomain" with your domain the last line can be modified to redirect a domain anywhere you want.
for example replacing the last line with :
RewriteRule ^(.*)$ http://www.google.com/url?sa=D&q=http://mydomain.com/index.php%3Fvalue%3D%251 [L,R] will result in visitors visiting "http://www.google.com/url?sa=D&q=http://example1.mydomain.com" to be taken to http://www.google.com/url?sa=D&q=http://mydomain.com/index.php%3Fvalue%3Dexample1
ok, all this will hapen provided you have already a folder named example1 in your file structure! I am trying to redirect people without having this folder there.
I tested my domain to see if it catches all subdomains by default by visiting foo.mydomain.com , it doesn't , i receive an error page. I thought i should modify the dns zones. I cannot do this in my main domain, as cpanel does not give that option. so i experiment using a domain un my whm I go to Main >> DNS Functions >> Edit DNS Zone in the whm . I add a zone *.mydomain.com. 1440 A 123.123.123.123 (my shared ip that is repeated in all the other entries)
after doing that, and using the htaccess file, example1.mydomain.com returns a blank page instead of an error page. I suspect this page is blank by default and is located somewher else, not in my directories. (maybe because i am on a shared hosting plan???)

A guy in the newsgroups told me this after watching a post of mine :
__________________________________________
In fact, before the request gets to the .htaccess file you have created, there are two important steps:
1. DNS (you have done this part)
*.domain.tld. 14400 IN A 123.123.123.123
2. Configure apache web server to handle wildcard subdomains and point them to one and the same location. Unfortunately for this part you need to have root whm account as cpanel won't allow resellers to modify httpd.conf. Anyway, you could ask your cpanel server administrator to add to you domain's VirtualHost section the wildcard directive. It should be appended to the line starting with ServerAlias. For example:
ServerAlias http://www.google.com/url?sa=D&q=http://www.domain.tld *.domain.tld

_______________________________________

I have done all this, so I came to a verdict.

I asked my host and unfortunately they will not do it.
So the verdict : If you have cpanel there is nothing you can do on your own to enabale catch-all subdomains.
If you have your own server or access to the virual hosts it can be done easily using the steps mentioned above.
Anyway, I hope this thread helps other people searching:)

0 Comments:

Post a Comment

<< Home