htaccess的 - 承载一个共享服务器上的多个域, [英] htaccess - hosting multiple domains on one shared server,

查看:246
本文介绍了htaccess的 - 承载一个共享服务器上的多个域,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个site1.com作为我的主站点。我创建的根目录下的站点1和放两个文件夹; 站点2。我用的.htaccess重定向site1.com的交通到文件夹站点1。站点2也工作作为site2.com使用目录中的站点2。

I have a site1.com as my primary site. I created two folders in the root directory "site1" & "site2". I used Htaccess to redirect site1.com's traffic to folder "site1". Site2 works too as site2.com using directory "site2".

现在,这个问题是因为s​​ite1的是主要的,我能够访问SITE2通过site.com/site2。我可以使用哪些重写忽略site.com/site2,或显示404时site1.com/site2被访问,仍然允许site2.com工作?

Now, the issue is because site1 is primary, I'm able to visit site2 via site.com/site2 . What rewrite can I use to ignore site.com/site2, or show a 404 when site1.com/site2 is visited and still allow for site2.com to work?

下面是我的htaccess文件。

Here is my htaccess file.

RewriteEngine叙述上 选项​​-MultiViews

RewriteEngine on Options -MultiViews

RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1/$1
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$ 
RewriteRule ^(/)?$ site1/index.php [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

我的文件夹层次结构

My folder hierarchy is

-root
    .htaccess 
    -site1 folder
          - index.php
    -site2 folder
          - index.php

由于GoDaddy的主域的设置,即使当我访问site.com加载信息从站点1文件夹,如果我访问site1.com/site2将加载网站2

Due to godaddy's primary domain setup, even though when i visit site.com it loads info from site1 folder, if i visit site1.com/site2 it will load site 2

推荐答案

未测试code:我相信你能做到以下

Untested code: I believe you can do the following

RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^site2/(.*)$ http://site1.com/$1 [R=301]

这将(或应该)重定向客户端从 http://site1.com/site2/my/awesome/page.php http://site2.com/my/awesome/page.php

This will (or should) redirect the client from http://site1.com/site2/my/awesome/page.php to http://site2.com/my/awesome/page.php.

这篇关于htaccess的 - 承载一个共享服务器上的多个域,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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