网站小节的多个域 [英] Multiple domains for site subsections

查看:81
本文介绍了网站小节的多个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是交易。基本上,我有多个域,我希望其中一个域指向站点的常规基础,而其他域指向站点的一个子部分,无需,无需修改网址地址栏。这个想法是,每个额外的域都为其部分标记了品牌。

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.

示例:

www.domain.com顶级网站

www.domain2.com指向www.domain.com/abc

www.domain3.com指向www.domain.com/def

等。

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.

还请注意,在示例中, abc和 def不是文件系统上的真实目录,而是数据库中定义的虚拟区域。

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 frames. 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?

编辑:

我已按照Mark的建议添加了别名,但是任何人都可以阐明我随后如何使用mod_rewrite来


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?

推荐答案

首先,您的DNS记录需要指向Web服务器的IP。

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

第二,您必须设置Apache以从同一VirtualHost提供多个域。启用mod_alias,然后在VirtualHost定义中使用ServerAlias指令。例如:

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.

接下来要做的是架构决定。您可以使用mod_rewrite根据域对URL路由规则进行硬编码,也可以使用PHP根据$ _SERVER ['HTTP_HOST']的值进行路由。

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'].

mod_rewrite解决方案可能需要向您的.htaccess文件中添加以下内容:

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.

这篇关于网站小节的多个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆