i am developing a website. where in user would be asked to select their country( like USA, UK, Australia & Canada in the websites landing page.
i am planning to create a sub-domain for each country. Now my query is,
开发者_如何学Cis it possible to run the website with these 4 sub-domain with the code and data bases in the main ROOT FOLDER
.
OR
do we need to install the code separately in all sub-domains and create the separate Data bases
.
Thanks in advance.
Regards, Gourav
You can so this with a .htaccess file which redirects to the correct part of the script when they come from any sub domain.
Checkout this page as is has a similar problem and solution you have:
http://blog.gwebtools.com/apache-htaccess-subdomain-redirect-rules/
Extract:
<IfModule mod_rewrite.c>
RewriteEngine On
#redirect gwebtools.com to www.gwebtools.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]
#if subdomain pt or whois and folder port-scanner redirect to pt.gwebtools.com/scanner-porta, with parameters
RewriteCond %{HTTP_HOST} ^(pt|whois)\.gwebtools\.com
RewriteRule ^port-scanner/* http://pt.gwebtools.com/scanner-porta$1 [R=301,L]
</IfModule>
Some information about .htaccess and some info so you can understand what the above code does: http://www.webweaver.nu/html-tips/web-redirection.shtml
Or you can do it in php like this tutorial:
http://php4every1.com/tutorials/multi-language-site/
You don't have to create anything seperate, but you would need to include the following in the application:
- Method to recognize WHICH subdomain is loaded (en.domain.com) for english language selection, etc.
- Create aliases for your domain (or just do a *.domain.com under apache for instance) to funnel the new subdomains into the proper virtual host.
- Create content specific to the subdomains (you can have one DB but pull distinct data based on which domain is being used -- again you would need to check for this in your app).
You could add a conditional code that checks $_SERVER["SERVER_NAME"]
variable somewhere and set the appropriate database settings based on the variable, without duplicating the code.
精彩评论