开发者

Multiple domains for site subsections

Here's the deal. Basically I've got multiple domains, and I would like one of the domains to point to the regular base of the site, but the other domains to point to a subsection of the site without modifying the url in the address bar. The idea is that each of the extra domains are branded for their section.

Example:

www.domain.com Top level of site

www.domain2.com points to www.domain.com/abc

www.domain3.com points to www.domain.com/def

etc.

Also note that in the example 'abc' and 'def' are not real directories on the filesystem, but are virtual areas defined in a database.

I've spent quite a bit of time looking around and couldn't find anything that fits this. I do not want to use domain cloaking because it uses fr开发者_高级运维ames. Regular redirects obviously are easy to point to the right thing, but they change the url in the address bar.

Is there any way to accomplish this?

Edit:

I've added the alias as Mark suggested below, but can anyone shed light on how I could then use mod_rewrite to make this work?


First, your DNS records need to point to the IP of the web server.

Second, you have to set up Apache to serve multiple domains from the same VirtualHost. Enable mod_alias and then use the ServerAlias directive in your VirtualHost definition. For example:

ServerName www.domain.com
ServerAlias domain.com www.domain2.com domain2.com www.domain3.com domain3.com

If you've done that correctly, you should see the exact same content at each domain, without any redirection.

What you do next is an architectural decision. You can use mod_rewrite to hard-code URL routing rules based on domain, or you can use PHP to do the routing, based on the value of $_SERVER['HTTP_HOST'].

A mod_rewrite solution might involve adding something like this to your .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} domain2\.com$
RewriteRule ^(.*)$ /abc/$1 [L]

RewriteCond %{HTTP_HOST} domain3\.com$
RewriteRule ^(.*)$ /def/$1 [L]

This is a high-level overview. Please comment on my answer if you need details on a particular part of the process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜