Mapping subdomains to parametered web pages in Apache

Mapping john.webserver.com to http://www.webserver.com/user.php?name=john
is just by changing a few parameters in http.conf file


In httpd.conf file,

<VirtualHost se.rv.er.ip.ad.re.ss>
        ServerAdmin info@servername.com
        DocumentRoot /var/www
        ErrorLog /var/log/apache/apache-error.log
        TransferLog /var/log/apache/apache.log
        ServerName www.servername.com
        ServerAlias *.servername.com
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^www.* [NC]
        RewriteCond %{HTTP_HOST} ^([^\.]+)\.servername\.com
        RewriteRule ^/$ http://www.servername.com/user.php?user=%1
</VirtualHost>


The lines for this feature,

RewriteEngine on activating rewrite option

RewriteCond %{HTTP_HOST} !^www.* [NC]  the rule will not be applied to subdomain "www"

RewriteCond %{HTTP_HOST} ^([^\.]+)\.servername\.com  subdomain section will be our parameter

RewriteRule ^/$ http://www.servername.com/user.php?user=%1  parameter section which is grabbed as subdomain name will be our value for user variable to user.php file.







You must be login first or sign-up for an account to post comments.

Maybe you should look at these also: