Unlimited subdomains based on mod_rewrite script

Emerican0525

Registered
Sep 2, 2012
1
0
1
cPanel Access Level
Root Administrator
Hello,

I am developing an application for a client who would like each registered user to have their own subdomain which points to the application. For example, say the clients name is bob then he should access the application via http://bob.domain.com.

To achieve this I am trying to use mod_rewrite with the following script:

RewriteEngine on
RewriteCond %{HTTP_HOST} ([^\.]+)\.domain\.com
RewriteRule ^(.*) /index.php?id=%1 [L]

I am adding the script using the apache configuration functionality in WHM and I am pasting the script in the "after all virtual hosts" part of the httpd configuration.

When I try access a subdomain for example test.domain.com, I keep getting the cPanel "Default Web Site Page" instead of the index page.

Any help will be greatly appreciated.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello :)

You can try modifying the application so that the subdomain is created automatically after a user is registered. This type of setup requires the use of our cPanel APIs, as documented here:

SubDomain
DomainLookup

Thank you.