php - 从根目录加载 .htaccess

标签 php apache .htaccess

所以我正在创建一个跨多个站点相同的模板系统,唯一改变的是配置文件。我正在制作所有文件都从根目录中获取。我可以用我所有的 php 和 html 文件来做到这一点,但我无法在我的 .htaccess 文件中找到它。目录的设置方式是/home/user_name/template,然后还有/home/user_name/site1.com 等文件夹以及所有站点外的文件夹。那么我怎样才能使所有站点都使用相同的 .htaccess 文件。我希望这是有道理的!

最佳答案

根据维基百科

A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration. They are placed inside the web tree, and are able to override a subset of the server's global configuration for the directory that they are in, and all sub-directories

来自 Oracle-Docs :

If you enable .htaccess files, the server checks for .htaccess files before serving resources. The server looks for .htaccess files in the same directory as the resource and in that directory's parent directories, up to and including the document root.

例如,

如果主文档目录设置为/oracle/server/docs

和一个

客户端请求/oracle/server/docs/reports/index.html,

服务器将检查:

.htaccess files at /oracle/server/docs/reports/.htaccess and /oracle/server/docs/.htaccess.

假设您有 2 个站点,并且您想使用一个文件为两个站点设置 .htaccess

然后只需创建如下文件结构

  • 家长
    • 站点 1
    • 站点 2
    • .htaccess

这里上传site1的所有数据site1文件夹等等。

关于php - 从根目录加载 .htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32468670/

相关文章:

regex - .htaccess 重定向和可见 URL

php - Wordpress 站点同时为不同域的 http 和 https 提供服务

python - WSGI/Django : pass username back to Apache for access log

php - 如何从 Active Directory 填充 Apache 服务器中的 REMOTE_USER(SSO 相关)

php - UTF-8贯穿始终

php - 具有多个 GET 变量的 .htaccess RewriteRule?

php - 在php中发送带附件的电子邮件而不将文件保存到网络服务器

PHP Like 函数与组合代码

javascript - 如何在 Firebase 中运行 PHP 脚本?

.htaccess - RewriteRule 和数字符号 “#”