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

Web*_*doz 1 php apache .htaccess trailing-slash url-redirection

我在我的网站的根文件夹下使用htaccess规则以删除文件扩展名并在末尾添加尾部斜杠.但是,我想从根文件夹htaccess规则中排除子目录/ sub-dir /.我试图将另一个htaccess添加到/ sub-dir /文件夹并放入RewriteOptions inheritRewriteEngine Off放在文件中,但它们都不起作用.

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]
Run Code Online (Sandbox Code Playgroud)

任何建议都非常感谢.

谢谢

Jon*_*Lin 7

您可以尝试在具有以下内容的子目录中添加htaccess文件:

RewriteEngine On
RewriteRule ^ - [L]
Run Code Online (Sandbox Code Playgroud)

没有任何继承选项.继承意味着您希望父htaccess中的规则也与子目录的htaccess文件中的任何规则一起应用.有了这个,你就可以确保重写引擎处于启用状态并制定"无所事事"的传递规则.

否则,您可以在根的htaccess文件的顶部添加passthrough(右下方RewriteBase):

RewriteRule ^sub-dir/ - [L]
Run Code Online (Sandbox Code Playgroud)