修改htaccess文件的两个站点 [英] Modify htaccess file for two sites

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

问题描述

我的虚拟主机指向我的主域名根WWW文件夹。该网站的文件,该站点位于网络/应用/根目录文件夹中。我现在有网站和使用下面的htaccess文件运行:

My web host points my "main" domain name to the root www folder. The web files for that site are located in the "www/app/webroot" folder. I currently have the site up and running using the following in the htaccess file:

RewriteBase /
RewriteEngine on
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L] 

我想开始开发站点为同一个站点。我做了一个在WWW文件夹命名为开发文件夹中。因此,网络文件这个文件夹是:WWW的/ dev /应用程序/ webroot的我有一个子域指向dev的文件夹。当我在dev的文件夹中使用相同的htaccess如上述,这是行不通的,因为(我相信)它是从根WWW文件夹继承设置。当页面加载,它只是出现空白。如何设置我的htaccess的文件,以便为这两个网站?

I'm trying to start a dev site for the same site. I made a folder named "dev" in the www folder. So, the web files for this folder are in: "www/dev/app/webroot" I have a sub-domain pointing to the dev folder. When I use the same htaccess as above in the dev folder, it doesn't work because (I believe) it is inheriting the settings from the root www folder. When the page loads, it just comes up blank. How do I set up my htaccess files to allow for both sites?

在此先感谢您的帮助!我显然是一个新手在这个东西。

Thanks in advance for any help! I'm obviously a novice at this stuff.

推荐答案

因此​​,我们会尽力清理东西: - )

So we'll try to clean the things :-)

避免使用的.htaccess。所有在目录/富/酒吧.htaccess中的设置可以在Apache配置被设置为一个目录设置(.haccess是有用的,如果你提供了在Apache的conf有限,如果你自己的服务器不使用它)。

Avoid using .htaccess. All the settings in a .htaccess in a directory /foo/bar can be set in apache configuration as a Directory setting (.haccess is usefull if you provide limited access on apache conf, if you own the server don't use it).

<Directory /foo/bar>(...)</Directory>

然后就可以使用名为基于virtualhosts访问您的网站。请验证您有这个选项:

Then you can access your sites with named based virtualhosts. Verify you have this option:

NameVirtualHost *:80

当你有好东西的就可以开始。 这将是你的虚拟主机为你的第一个应用程序:

When you have it nice things can start. This will be your virtualhost for your 1st app:

<VirtualHost *:80>
    ServerName app
    ServerAlias www.app.somwhere.com
    ServerAlias app.somwhere.com
    DocumentRoot /www/app/webroot
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /www/app/webroot>
        Options Indexes FollowSymLinks
        # this prevent.htaccess reading, remove if you want .htaccess
            AllowOverride None
            # allow web access 
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

大多数apache的设置可以定义在这里。只为你的第一个应用程序。 Apache将服务于该站点名称应用程序或www.app.somwhere.com'或'app.somwhere.com所做的所有请求此配置。您可以定义很多别名( ServerAlias​​ ),并且只有一个名字(服务器名称)。

Most apache settings can be define here. Only for your 1st app. Apache will serve this configuration for all requests done for the site name 'app', or 'www.app.somwhere.com', or 'app.somwhere.com'. You can define a lot of alias(ServerAlias)., and only one name (ServerName).

然后如果你走在你的浏览器并输入的http://应用程序/ 您的浏览器将无法找到服务器,所以设置在你的/ etc / hosts中。这是每个人想访问你的应用程序应该在hosts文件,直到你得到一个真实的DNS(假设你的第一个应用程序是app.somwhere.com第二foo.somwhere.com和92.128.52.226is你的外部IP)

Then if you go in your browser and type http://app/ your browser won't find the server, so set it in your /etc/hosts. This is what every people wanting to access your app should have in the hosts file until you get a real DNS (assuming your 1st app is app.somwhere.com and the second foo.somwhere.com and 92.128.52.226is your external IP):

127.0.0.1 app.somwhere.com app foo foo.somewhere.com
92.128.52.226 app.somwhere.com app foo foo.somewhere.com

现在,让我们添加另一个虚拟主机为你的第二个应用程序:

And now let's add another virtualhost for your second app:

<VirtualHost *:80>
    ServerName foo
    ServerAlias www.foo.somwhere.com
    ServerAlias foo.somwhere.com
    DocumentRoot /www/foo/webroot
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /www/foo/webroot>
        Options Indexes FollowSymLinks
        # this prevent.htaccess reading, remove if you want .htaccess
            AllowOverride None
            # allow web access 
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

等。 不要忘记重启你的Apache。没有重写规则。漂亮virtualhosts是一个不错的配置的第一个步骤中,您将能够确定每个使用的名称规则,目录或位置具体的事情。甚至是PHP配置可以为每个虚拟主机被设置php_value而不是在php.ini中的全局共享的。

And etc. Don't forget to restart your apache. No rewrite rule. nice virtualhosts is the 1st step of a nice configuration, you will be able to define rules, directory or location specific things per name used. Even php configuration can be set per virtualhost with php_value instead of a global shared one on php.ini.

键入

apache2 -S

让你virtualhosts的列表,你会看到,第一个是默认的,如果Apache一点儿也不了解请求站点的名称,将服务于这个默认的(所以你可以广告一个在顶部的特定的虚拟主机来处理论文的情况下)。

to get the list of your virtualhosts, you'll see that the first one is the 'default' one, if apache does'nt understand the name of the requested site it will serve this default one (so you could ad a specific virtualhost on top to handle theses cases).

这篇关于修改htaccess文件的两个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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