Creating a catch all sub domain system

Ok recently i needed a catch all system for a website i was creating. All the tutorials i went through needed me to change the httpd.conf file. Pretty hard to do when on shared hosting. But found the solution to it using CPanel functions.

Instead of adding *.domain.com to the httpd.conf file

ServerAlias www.domain.com domain.com *.domain.com

Answer below

You can create a subdomain using the cpanel function with * as the subdomain title. You can set it’s fileroot as public_html to redirect to the root folder, or set up as something else.

if you want an example of htaccess that would send the subdomain to the script –

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) $1?subDomain=%2 [L]

</IfModule>

You can leave a response, or trackback from your own site.

Leave a Reply