| CATEGORIES |
| PHP ARTICLES |
|
Browse All PHP Articles
Latest Articles |
|
<< All Php Articles
|
|||
|
|
|||
| Creating subdomains dynamically with .htaccess | |||
|
| |||
|
This tutorial presents a way to create subdomains dynamically using .htaccess You will be able to change the way you access a page from 'www.site.com/subdomain' to 'www.subdomain.site.com' Say we have, for example, a site where users are able to create thier own sites (which are accesed with 'www.site.com/usersite/' - these subdomains are practically virtual, there's no folder created for each site, you handle the user site by redirecting /usersite to a usersite.php, which is the default index for usersites and from there you handle requests, ...). Ok, to change 'www.site.com/usersite/' to 'www.usersite.site.com' here's what you have to do (remember, we have index.php - main site index, usersite.php - user site index): From cPanel, Sub-domains section, create a new subdomain and name it '*'. Now open .htaccess and copy-paste this somewhere after RewriteEngine On (change usersite.php, site.com to yours) RewriteCond %{REQUEST_URI} !^/usersite\.php RewriteCond %{HTTP_HOST} !^www\.site\.com RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.site\.com RewriteRule ^$ /usersite.php?action=...&other_var=%1 [L] #%1 - is the name of the domain For each RewriteRule you want to edit for the 'user site' you have to write the 3 RewriteCond expressions, and for each rule referring the main site, you need to write the following RewriteCond: RewriteCond %{HTTP_HOST} !^www\.([^.]+)\.site\.com |
|||
| << All Php Articles |