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

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

问题描述

我的网络主机将我的主"域名指向根 www 文件夹.该站点的 Web 文件位于www/app/webroot"文件夹中.我目前使用 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 文件夹中创建了一个名为dev"的文件夹.因此,此文件夹的 Web 文件位于:www/dev/app/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.目录/foo/bar 中 .htaccess 中的所有设置都可以在 apache 配置中设置为目录设置(如果您提供对 apache conf 的有限访问,则 .haccess 很有用,如果您拥有服务器,请不要使用它).

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>

然后您可以使用基于命名的虚拟主机访问您的站点.确认您有此选项:

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 将为针对站点名称app"、www.app.somwhere.com"或app.somwhere.com"完成的所有请求提供此配置.您可以定义很多别名(ServerAlias),并且只能定义一个名称(ServerName).

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://app/,您的浏览器将找不到服务器,因此将其设置在您的/etc/hosts.conf 中.这是每个想要访问您的应用程序的人都应该在主机文件中拥有的内容,直到您获得真正的 DNS(假设您的第一个应用程序是 app.somwhere.com,第二个 foo.somwhere.com 和 92.128.52.226 是您的外部 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.没有重写规则.nice virtualhosts 是一个好的配置的第一步,你将能够定义规则、目录或位置特定的东西使用的名称.甚至可以使用 php_value 为每个虚拟主机设置 php 配置,而不是 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

要获取您的虚拟主机列表,您会看到第一个是默认"的,如果 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天全站免登陆