使用相同内容的多个域 [英] Multiple domains using same content

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

问题描述

我有一个使用主域(domain.com)的应用程序,我希望能够将其他域指向相同的内容,而无需维护代码的单独实例.该应用程序包含在主域中的文件夹中,搜索引擎等无法访问此文件夹,因此我不必担心SEO等.所有域都将在运行Apache的同一服务器上.

I have an application which uses a main domain (domain.com) and I want to be able to point other domains to the same content without needing to maintain separate instances of the code. The application is contained with a folder on the main domain and this folder is not accessed by search engines etc so I am not worried about SEO etc. All of the domains will be on the same server running Apache.

我想确保域名保持用户最初输入时的状态,而不是重定向到domain.com,因为这样做的目的是让多个客户可以使用该代码,但应用程序使用其颜色来标记他们的名字,徽标等使用从MySQL数据库获取的设置.

I would like to ensure that the domain name stays as the user originally typed it rather than redirect to domain.com as the purpose of this is so multiple customers can use the code but with the application branded to them using their colours, logo etc using settings taken from a MySQL database.

例如,用户转到newdomain.com,他们看到一个登录表单,该表单是存储在/home/newdomain/public_html中的本地表单-成功登录后,他们将定向到包含应用程序的/folder,而不是被定向到newdomain.com/folder为空,我希望将它们重定向到domain.com/folder(即/home/domain/public_html/folder),但仍在浏览器中看到newdomain.com/folder,因此对他们透明

For example, a user goes to newdomain.com and they see a login form which is a local stored within /home/newdomain/public_html - on successful login they are directed to /folder which contains the application but rather than be directed to newdomain.com/folder which is empty I would like them to be redirected to domain.com/folder (i.e. /home/domain/public_html/folder) but still see newdomain.com/folder in their browser so it is transparent to them.

我使用htaccess尝试了以下 https://stackoverflow.com/a/9521102/1278201 ,但它更改了指向domain.com的网址:

I tried the below https://stackoverflow.com/a/9521102/1278201 using htaccess but it changes the URL to domain.com:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/%{REQUEST_URI} [R=301,L]

我还发现了一个使用Apache config的帖子,这似乎是一个更好的选择,因为我不关心SEO,但不确定是否可以使用它仅重定向一个文件夹(即,不重定向webroot,仅重定向/文件夹) https://stackoverflow.com/a/3849129/1278201 :

I also found a post which mentioned using Apache config which seemed a better option as I am not concerned about SEO but am not sure if I can use this to only redirect one folder (i.e. don't redirect webroot, just redirect /folder) https://stackoverflow.com/a/3849129/1278201:

NameVirtualHost *

<VirtualHost *>
ServerName domain.com
DocumentRoot /home/domain/public_html/folder
</VirtualHost>

<VirtualHost *>
ServerName newdomain.com
DocumentRoot /home/domain/public_html/folder
</VirtualHost>

我还发现了一些帖子,指出了会话和SSL证书可能存在的问题 https://stackoverflow.com/a/140008/1278201 都在应用程序中使用.我很乐意为每个域安装一个单独的SSL证书,但是上述任何重定向都可以重定向中断"会话吗?如果有人登录到newdomain.com/folder然后转到domain.com/folder,这很麻烦,他们将需要再次登录,但是domain.com/folder重定向到newdomain.com/folder的事实会影响会话安全性?

I also found posts pointing out possible issues with sessions and SSL certificates https://stackoverflow.com/a/140008/1278201 both of which are used in the application. I am happy to install a separate SSL certificate per domain but could any of the above redirects "break" sessions? Obvioulsy if someone logs in to newdomain.com/folder and then goes to domain.com/folder they would need to login again but would the fact that domain.com/folder is redirecting to newdomain.com/folder have an impact on session security?

达到预期结果的最佳方法是什么?

What is the best way to achieve the desired outcome?

推荐答案

您可以使用'P'(代表proxypass)作为标记,而不是'R = 301':

You can use 'P' (stands for proxypass)as flag instead of 'R=301' :

RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [P,L]

还将虚拟主机更改为单个主机:

Also change the virtual hosts to single one :

NameVirtualHost *

<VirtualHost *>
    ServerName domain.com
    ServerAlias www.domain.com newdomain.com www.newdomain.com
    DocumentRoot /home/domain/public_html/folder
</VirtualHost>

这篇关于使用相同内容的多个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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