简体   繁体   English

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

[英].htaccess in subdirectory 'overriding' parent htaccess

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. 由于我缺乏对mod_rewrite的理解以及该项目的时间限制,因此已经搜索了2天,却无法获得正确的解决方案,希望有人能提供帮助。

The aim 目的

To rewrite all requests to the root index.php if the client doesn't have the correct cookie. 如果客户端没有正确的cookie,将所有请求重写到根index.php。 If the client has the correct cookie allow them to browse as they wish. 如果客户端具有正确的cookie,则允许他们根据需要进行浏览。

The problem 问题

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优先于我的根htaccess,因此诸如www.mydomain.com/subdir/index.php之类的请求都不会被重定向。

My root .htaccess 我的根.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]

My subdir htaccess 我的子目录htaccess

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

Additional info 附加信息

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. 理想情况下,我正在尝试创建一个密码保护区域,因此所有请求都路由到index.php,可以在其中输入密码,并在验证后创建cookie,从而允许免费浏览内容和子目录。 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. 因此,如果有更好的方法可以做到这一点,请告诉我,由于我需要自定义登录,错误和启动页面,所以我没有使用.htpasswd。

Also, the subdir .htaccess is an ExpressionEngine URL handler. 同样,子目录.htaccess是ExpressionEngine URL处理程序。

Thanks. 谢谢。

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(父文件夹的htaccess)执行重写规则,您需要明确允许它(Apache将当前.htaccess中的重写规则视为唯一需要执行的规则,只要重写的URL保留在其中即可。相同的子文件夹)。

You need to add this line to your .htaccess in sub-folder: 您需要将此行添加到子文件夹的.htaccess中:

RewriteOptions inherit

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM