从子主机主域 [英] Host Primary Domain from a subfolder

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

问题描述

我有一个问题作出子目录充当的public_html为我的主要领域,并获得了工程与太域子目录的解决方案。

I am having a problem making a sub directory act as the public_html for my main domain, and getting a solution that works with that domains sub directories too.

我的主机让我承载多个站点,全部伟大的工作。我已经下设立一个子文件夹我的〜/的public_html / 目录中名为 /域/ ,我在那里创建每个单独的网站的文件夹。我的服务器上的文件夹结构看起来是这样的:

My hosting allows me to host multiple sites, which are all working great. I have set up a subfolder under my ~/public_html/ directory called /domains/, where I create a folder for each separate website. The folder structure on my server looks something like this:


  • 的public_html



      • websiteone

      • websitetwo

      • websitethree

      • ...

      这使我的网站好和整洁。唯一的问题是让我的主域名来融入这个体系。看来我的主要领域,以某种方式连接到我的帐户(或Apache的,或某事),所以我不能改变这个领域的文档根目录。我可以把文档根目录为我的cPanel没有添加任何问题,其他领域(插件域)。但主要的领域是不同的。

      This keeps my sites nice and tidy. The only issue was getting my "main domain" to fit into this system. It seems my main domain, is somehow tied to my account (or to Apache, or something), so I can't change the "document root" of this domain. I can define the document roots for any other domains ("Addon Domains") that I add in cPanel no problem. But the main domain is different.

      我被告知编辑.htaccess文件,重定向主域名到子目录。这似乎工作的伟大,和我的网站能正常工作它的家/索引页。

      I was told to edit the .htaccess file, to redirect the main domain to a subdirectory. This seemed to work great, and my site works fine on it's home/index page.

      我遇到的问题是,如果我尝试浏览我的浏览器说我的主网站的图像文件夹(只是举例),如下所示:

      The problem I'm having is that if I try to navigate my browser to say the images folder (just for example) of my main site, like this:

      www.yourmaindomain.com/images /

      www.yourmaindomain.com/images/

      那么它似乎忽略重定向并显示在url整个服务器的目录,如:

      then it seems to ignore the redirect and shows the entire server directory in the url, like this:

      www.yourmaindomain.com/domains/yourmaindomain/images /

      www.yourmaindomain.com/domains/yourmaindomain/images/

      这实际上仍然显示页面正确的/图片索引,并显示出我所有的图像列表。这仅仅是prettyURL这就是问题所在。

      It still actually shows the correct "Index of /images" page, and shows the list of all my images. It's just the "pretty" URL that's the problem.

      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
      RewriteCond %{REQUEST_URI} !^/domains/yourmaindomain/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /domains/yourmaindomain/$1
      
      RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
      RewriteRule ^(/)?$ domains/yourmaindomain/index.html [L]
      

      这是否htaccess文件看起来是正确的?我只需要使它所以我的主要领域表现得像一个附加域,它的子目录坚持重定向规则。

      Does this htaccess file look correct? I just need to make it so my main domain behaves like an addon domain, and it's subdirectories adhere to the redirect rules.

      推荐答案

      不要使用mod_rewrite为,使用的虚拟主机了解这一点。我就不解释了,这里详细,你会发现在上面的链接所有必要的信息。 (提示:你需要基于域名的那些可能)

      Don't use mod_rewrite for that, use virtual hosts for that. I won't explain that here in detail, you'll find all the necessary information at the above link. (Hint: You'll need the name-based ones probably.)

      您可能想出来〜/的public_html / 的移动你的东西,像 /无功/网络/ / SRV /网络

      You probably want to move your stuff out of ~/public_html/ to some more generic place like /var/www/ or /srv/www.

      除此之外:不要使用。生产的htaccess 文件。

      Besides that: Don't use .htaccess files on production.

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

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