子目录“覆盖"父 htaccess 中的 .htaccess

.htaccess in subdirectory #39;overriding#39; parent htaccess(子目录“覆盖父 htaccess 中的 .htaccess)
本文介绍了子目录“覆盖"父 htaccess 中的 .htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

搜索了 2 天,由于我对 mod_rewrite 缺乏了解,而且这个项目的时间限制,因此无法完全找到正确的解决方案,因此希望有人能提供帮助.

been searching for 2 days and can't quite get the right solution due to my lack of understanding of mod_rewrite and time constraints on this project so hoping someone can help.

目标

如果客户端没有正确的 cookie,则将所有请求重写到根 index.php.如果客户端拥有正确的 cookie,则允许他们随意浏览.

To rewrite all requests to the root index.php if the client doesn't have the correct cookie. If the client has the correct cookie allow them to browse as they wish.

问题

我的子目录中的 htaccess 优先于我的根 htaccess,因此诸如 www.mydomain.com/subdir/index.php 之类的请求不会被重定向.

The htaccess in my subdirectory is taking precendence over my root htaccess, so requests such as www.mydomain.com/subdir/index.php arn't getting redirected.

我的根 .htaccess

Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !^.*pass.*$ 
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ http://www.mydomain.com/index.php?url=$0 [NC]

我的子目录 htaccess

RewriteEngine On
RewriteBase /
RewriteCond $1 !.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

其他信息

理想情况下,我正在尝试创建一个密码保护区域,因此所有请求都被路由到 index.php,可以在其中输入密码,并在验证后创建 cookie,允许自由浏览内容和子目录.因此,如果有更好的方法来完成此操作,请告诉我,我没有选择 .htpasswd,因为我需要自定义登录、错误和启动页面.

Ideally I'm trying to create a password protected area, so all requests are routed to index.php where a password can be entered and when verified a cookie is created, allowing free browsing of contents and sub directories. So if there is a better way to accomplish this then please let me know, and I havn't gone for .htpasswd since I need custom login, error and splash pages.

此外,子目录 .htaccess 是 ExpressionEngine URL 处理程序.

Also, the subdir .htaccess is an ExpressionEngine URL handler.

谢谢.

推荐答案

要允许从父 .htaccess 执行重写规则(htaccess from parent folder),您需要明确允许它(Apache 将处理当前 .htaccess 中的重写规则作为唯一需要执行的,只要重写的 URL 保留在同一个子文件夹中即可).

To allow execution of rewrite rules from parent .htaccess (htaccess from parent folder), you need to explicitly allow it (Apache will treat rewrite rules in current .htaccess as the only one that need to be executed, as long as rewritten URL remains in the same subfolder).

您需要将此行添加到子文件夹中的 .htaccess 中:

You need to add this line to your .htaccess in sub-folder:

RewriteOptions inherit

Apache 手册:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions

这篇关于子目录“覆盖"父 htaccess 中的 .htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)