Subdomains with .htaccess - NBS






 

 

Subdomains with .htaccess - NBS

View Full Version : Subdomains with .htaccess


DR_GIGGULS
30-Jul-2007, 11:25 AM
Hello.

For this thing you must have wildcard dns and mod_rewrite enabled.

.htaccess:

DirectoryIndex new_forum.php index.php index.html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ handler.php?_url=$1&%{QUERY_STRING} [L]

rewriteBase /
rewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
rewriteCond %{HTTP_HOST} !^www\.domain\.com
rewriteRule ^$ /%1

Obviously you have to replace "domain" with your domain.
You save this as .htaccess and replace the original NBS one.

Changelog:
27.09.2007:
- now opening your domain will open the new_forum.php page
- if new_forum.php does not exist, the indexes will be the default ones

Done.
Tested and works fine.

king master
23-Sep-2007, 07:30 PM
i don't have wildcard dns

not working 4 me

:(

Gijs
16-Feb-2008, 05:05 PM
In the code is it: www\.domain\.com, do I need to place te backslashes?

zellfaze
18-Feb-2008, 05:36 PM
i don't have wildcard dns

not working 4 me

:(

Having wild card DNS is a must, wild card DNS allows subdomains to be accessed without having been specifically setup.

DR_GIGGULS
18-Feb-2008, 07:12 PM
In the code is it: www\.domain\.com, do I need to place te backslashes?

Yes, if your domain is www.nbsdesignz.com, it will look like that: www\.nbsdesignz\.com


i don't have wildcard dns

not working 4 me

:(

Contact your hosting provider, they may enable it for you. It is not enabled by default on any hosting. And, yes, you HAVE TO have it enabled to use this feature.

agent_smith
25-Mar-2008, 06:28 PM
Thier is such an easy solution to having subdomains with any script with multiple tables + wildcard dns.

Just use php in the config file, get the subdomain in the url, process it in php to get all the tables which use the subdomain prefix.