简体   繁体   English

从根文件夹的htaccess规则中排除子目录

[英]exclude sub directory from htaccess rules in root folder

I am using below htaccess rules on my website's root folder to remove the files extensions and add trailing slash at the end. 我正在网站根目录下使用htaccess规则,以删除文件扩展名并在末尾添加斜杠。 However, I'd like to exclude a sub-directory /sub-dir/ from the root folder htaccess rules. 但是,我想从根文件夹htaccess规则中排除子目录/ sub-dir /。 I tried to add another htaccess to the /sub-dir/ folder and put RewriteOptions inherit or RewriteEngine Off in the file but none of them works. 我试图将另一个htaccess添加到/ sub-dir /文件夹中,并将RewriteOptions inheritRewriteEngine Off放在文件中,但是它们都RewriteOptions inherit

RewriteEngine On
RewriteBase /

# redirect from non-www to www
RewriteCond %{HTTP_HOST} ^mywebsite.com.au$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com.au/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule ^(.*)index.php$ http://www.mywebsite.com.au/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.php [L]

# Remove trailing slash:
RewriteRule (.*)/$ $1 [L]

# Now test without the trailing slash:
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_FILENAME}.php [QSA,L]

Any suggestion is highly appreciated. 任何建议都将受到高度赞赏。

Thanks 谢谢

You can either try adding an htaccess file in your subdirectory that has only this: 您可以尝试在具有以下内容的子目录中添加htaccess文件:

RewriteEngine On
RewriteRule ^ - [L]

Without any inherit options. 没有任何继承选项。 Inherit means you want the rules in the parent htaccess to also be applied along with any rules in the subdirectory's htaccess file. 继承表示您希望父htaccess中的规则也与子目录的htaccess文件中的任何规则一起应用。 With this, you're making sure the rewrite engine is on and making a "do nothing" pass-through rule. 这样,您可以确保重写引擎已打开,并制定了“不执行任何操作”传递规则。

Otherwise, you can add the passthrough at the top of the root's htaccess file (right below RewriteBase ): 否则,您可以在根目录的htaccess文件(位于RewriteBase正下方)的顶部添加RewriteBase

RewriteRule ^sub-dir/ - [L]

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

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