Dynamic subdomains with Wildcard DNS?


#1

Hi,

I’d like to create multiple subdomains on my Dreamhost PS without having to add each one manually in the panel. It was suggested by support that this could be possible with wildcard DNS. I had them setup wildcard DNS on a domain so I could try this out.

My question is in regards to this page from the Dreamhost wiki: http://wiki.dreamhost.com/Dynamic_Subdomains

So far I have done this:

  1. Enabled wildcard DNS for: mydomain.com
  2. Created a subdomains folder here: mydomain.com/subdomains
  3. Created a /test folder inside the /subdomains folder (mydomain.com/subdomains/test).
  4. Put an .htaccess file in mydomain.com/.htaccess containing the example in the wiki above (replacing example.com with mydomain.com)

Am I correct in my understanding of the wiki page that I should now be able to visit test.mydomain.com, and view the index.php page residing here: mydomain.com/subdomains/test/index.php

I have completed all 4 steps above, but when I visit test.mydomain.com, I get this error in my browser:

“Firefox has detected that the server is redirecting the request for this address in a way that will never complete.”

Does anybody have any idea what I could be doing wrong? Or if I may have missed a step?


#2

It might be a case that Support have configured a ServerAlias within the httpd.conf, but you must still add the WildCard to the DNS Zone for your domain. You can check the zone via Panel for the presence of *.domain.com.

What’s your base domain URL?

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#3

Hi sXi, thanks for your reply. I checked in the panel under DNS settings, and * CNAME mydomain.com. has indeed been added.

I’m pretty shaky on this subject, but it seems the DNS is setup alright, as when I delete the .htaccess file and visit “test.mydomain.com” or any other random subdomain (*.mydomain.com) in the browser, I see the index.php file residing in the root of the domain: mydomain.com/index.php

Maybe there is an issue with the way I setup the .htaccess code from the wiki page: http://wiki.dreamhost.com/Dynamic_Subdomains

Anyway, I’ll PM you my base domain URL info, along with the exact code I’m using in the .htaccess file, just in case you’d like to take a look.

Thanks again for your help.


#4

I ran a quick online test on the domain you supplied and WildCard DNS does appear to be functioning as expected. Maybe check (again) line-for-line your .htaccess directives against the proposed method in the Wiki article.

btw, I haven’t read the article in it’s entirety, but I did notice by hitting “History” that the last edit was performed fairly recently and the user who changed it apparently didn’t edit any of the methodology within the instructions. That isn’t to say they had first tested the method themselves, of course, so there might be some tweaking to be done to get it to work correctly in your environment.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#5

Thanks again.

I went over the .htaccess code from the Wiki above, and could not find anything different from what I had residing in the root of my domain (minus replacing “example.com” with my domain). I read over several mod-rewrite tutorials, but I’m no .htaccess guru, and was unfortunately unable to diagnose what (if anything) is wrong with the proposed code on the Wiki page.

However, I was able to find something that works. It’s from the 5th post (by “rkrause”) in this thread: http://www.webmasterworld.com/apache/3163397.htm

To get it to work on my Dreamhost PS, I added Options +FollowSymLinks and RewriteEngine On. The complete working code in my .htaccess file is now this:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+).mydomain.com.?(:80)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subdomains/%1 -d
RewriteRule ^(.*) subdomains/%1/$1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]

I can now go to “test.mydomain.com”, and see the website which is actually residing in “mydomain.com/subdomains/test”. Hope this helps anyone else who may have a similar problem in the future.