.htaccess:多个.htaccess文件如何工作? [英] .htaccess: how do multiple .htaccess files work?

查看:220
本文介绍了.htaccess:多个.htaccess文件如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在CakePHP的上下文中,但是我确定它在其他应用程序中很常见。我执行了此页面上的说明:

This is in context of CakePHP, but I'm sure it is common in other applications. I implemented the instructions on this page:

http://book.cakephp.org/view/917/Apache-and-mod_rewrite-and-htaccess

A:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ app/webroot/ [L]
    RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

B:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
</IfModule>

C:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

在第3节中,有3个.htaccess文件。为了简单起见,我们仅将它们称为A,B和C。尽管它似乎可以在我的服务器(localhost XAMPP)上运行,但是我不确定是否了解重定向的路径。无论我输入什么地址,它总是按应有的方式进入localhost\cake\users\login。

In section 3, there are 3 .htaccess files. Let's just call them A, B, and C in order for simplicity. Although it seems to be working on my server (localhost XAMPP), I'm not sure if I understand the path of the redirects. Whatever address I type in, it always go to localhost\cake\users\login as it's supposed to.

我的应用程序的根目录的位置驻留的是蛋糕。我分别带有A,B和C的\cake,\cake\app和cake\app\webroot。按照上述说明操作后,cake wantapp中的代码将运行,这就是我想要的。在像上面那样正确设置.htaccess文件之前,正在运行\cake中的代码。这是不正确的,因为它告诉我我的数据库未设置,您没有此文件,等等。

Root directory of my application in terms of where it resides is \cake. I have \cake, \cake\app, and cake\app\webroot with A, B, and C, respectively, in them. After following the above instruction, the codes in cake\app run, which is what I want. Prior to setting up the .htaccess files correctly like above, codes in \cake were being run; this was incorrect as it was telling me my database wasn't setup, you don't have this file, etc.

有人可以鸣叫并帮助我解决此应用程序正在运行任何php文件的路径之前是 吗?是否将所有内容都重定向到cake\app\webroot,然后再重定向到.htaccess文件之外设置的任何重定向? (在这种情况下,要结结用户登录名)

Can someone chime in and help me out with the "path" this application is taking before running any php files? Is it redirecting everything to cake\app\webroot, then to whatever redirect is setup beyond the .htaccess files from there? (in this case, to cake\users\login)

感谢您的帮助!

PS:我很to愧地说我仍然没有弄清楚哪个文件的哪一部分重定向到用户登录页面的所有HTTP请求。我在不久前进行了设置,然后又回到了它。我想我是在CakePHP Cookbook页面上的第二篇教程中添加了ACL功能。

PS: I'm ashamed to say I still haven't figured out which part of which file is redirecting to all of the HTTP request to the user login page. I set this up a while ago, and I just came back to it. I think I was following the second tutorial on the CakePHP Cookbook page where you add an ACL feature..

推荐答案


在运行任何php文件之前,有人可以鸣叫并帮助我解决该应用程序采用的路径吗?是否将所有内容都重定向到cake\app\webroot,然后再重定向到.htaccess文件之外设置的任何重定向? (在这种情况下,登录用户帐户)

Can someone chime in and help me out with the "path" this application is taking before running any php files? Is it redirecting everything to cake\app\webroot, then to whatever redirect is setup beyond the .htaccess files from there? (in this case, to cake\users\login)

总之,是的。只是一个执行 real 工作的 .htaccess 文件,即 C(这是 /中的文件app / webroot / .htaccess )。这会将所有非对现有文件或目录的请求传递给 index.php ,后者引导CakePHP并处理该请求。任何进一步的重定向都由 CakePHP的路由处理。

In short, yes. There is only one .htaccess file doing the real work, and that is "C" (which is the file in /app/webroot/.htaccess). This passes any requests that aren't for an existing file or directory to index.php which bootstraps CakePHP and handles the request. Any further "redirection" is handled by CakePHP's routing.

编辑:
要解决有关重定向到登录页面的问题,您可能已经配置了验证组件,并且尚未通过 $ this-> Auth-> allow()

To address your question about what's redirecting to the login page, chances are you have configured the Auth component and haven't set any "public" pages via $this->Auth->allow().

如果您将CakePHP安装目录或app目录放在Apache用来提供服务的文件夹中,则另外两个会存在页面,例如 / var / www / html 或类似名称。您会注意到该结构为:

The other two are there in case you put the CakePHP installation directory or the app directory into a folder that is used by Apache to serve pages, e.g. /var/www/html or similar. You'll note that the structure is:


/cakephp-1.3.x/.htaccess ( A)

/cakephp-1.3.x/app/.htaccess ( B)

/cakephp-1.3.x/app/.htaccess ("B")

/cakephp-1.3.x/app/webroot/.htaccess ( C)

/cakephp-1.3.x/app/webroot/.htaccess ("C")

因此,所有这些级别的任何请求最终都将由 C中的RewriteRule处理。这样做是为了保护敏感数据,例如数据库连接信息,并确保应用程序正常运行(因为所有请求都应通过CakePHP引导程序进行,除非您已设置自定义路由)。

So, any request at any of these levels will end up being handled by the RewriteRule in "C". This is done to protect sensitive data such as your database connection information and ensure the application functions properly (as all requests should go through the CakePHP bootstrapper, unless you've set up custom routing).

这篇关于.htaccess:多个.htaccess文件如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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