简体   繁体   English

.htaccess索引阻止的怪异行为

[英]Weird behaviour of .htaccess index blocking

I had some problems with excluding a folder from the index block in the .htaccess file in my site's root folder. 我在站点根文件夹的.htaccess文件的索引块中排除了一个文件夹时遇到了一些问题。

After messing around a bit, I found a solution: 经过一番混乱之后,我找到了解决方案:

<IfModule mod_rewrite.c>
   RewriteEngine on
</IfModule>

I wrote this in an new .htaccess file in the folder that I wanted to be excluded. 我在一个我想排除的文件夹中的新.htaccess文件中编写了此文件。 This solved my problem (unblocking that specific folder while keeping the subfolders blocked) which is great and all but as far as I know, this piece of code shouldn't do anything. 这解决了我的问题(取消阻止该特定文件夹同时阻止子文件夹),这很好,但就我所知,这部分代码什么都不做。 How could this possibly work? 这怎么可能起作用?

Additional information: 附加信息:
- the excluded folder contains a Nibbleblog installation -排除的文件夹包含Nibbleblog安装
- root .htaccess file: -根.htaccess文件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

RewriteCond %{HTTPS} !^on$ 
RewriteRule (.*) https://url.url/$1 [R,L]

RewriteCond %{HTTP_HOST} ^www\.nyxcode\.xyz [NC]
RewriteRule (.*) https://url.url/$1 [R=301,L]

ErrorDocument 404 /errors/notfound.html
ErrorDocument 403 /errors/forbid.html

Options -Indexes

By adding RewriteEngine on to a .htaccess file in a subfolder, you've told Apache that the parent folder's .htaccess doesn't control rewriting in the subfolder. 通过将RewriteEngine on添加到子文件夹中的.htaccess文件,您已经告诉Apache父文件夹的.htaccess不能控制子文件夹中的重写。 This is because Apache checks the folder that matches the URL first, and only then looks in the parent folder. 这是因为Apache首先检查与URL匹配的文件夹,然后才在父文件夹中查找。

If you have this: 如果您有这个:

/
   .htaccess
   /subfolder1
       .htaccess
   /subfolder2
       # no .htaccess file here

Then files in / and /subfolder2 are subject to the RewriteRule s in /.htaccess . 然后, //subfolder2/.htaccessRewriteRule /.htaccess But /subfolder1 is subject only to its own .htaccess file, to the extent that it applies. 但是/subfolder1仅在适用的范围内受其自己的.htaccess文件约束。 Without RewriteEngine on , you haven't told Apache that the /subfolder1/.htaccess applies for rewriting purposes. 如果没有RewriteEngine on ,则不会告诉Apache /subfolder1/.htaccess适用于重写。 With RewriteEngine on , you're saying, "Use this .htaccess for rewriting," even if there are no rules there. RewriteEngine on ,您说的是“使用此.htaccess进行重写”,即使那里没有规则。

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

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