gpt4 book ai didi

php - 将 .htaccess 应用于所有子目录

转载 作者:行者123 更新时间:2023-12-05 03:11:11 26 4
gpt4 key购买 nike

我有以下目录结构:

root
folder1
foldera
file.php
folder2
folderb
index.php
.htaccess

我想将所有请求路由到 index.php 并将其应用于所有文件夹。这是我的 .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

这似乎适用于 localhost/root。请求已正确路由到 index.php。但是对于 localhost/root/folder1localhost/root/folder1/foldera/filephp 它不起作用。我是否需要定义其他规则才能使其正常工作?

最佳答案

发件人:https://httpd.apache.org/docs/current/howto/htaccess.html

The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.

如果您的 htaccess 位于根目录中,为什么要使用“../”?就目前而言,它正在重定向到根目录上方的 index.php。

如果您希望它适用于所有请求,请删除两个重写条件。现在它说:“仅当请求不是针对存在的文件或目录时才重写请求”。

关于php - 将 .htaccess 应用于所有子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37802476/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com