我在我网站的根文件夹上使用以下 htaccess 规则来删除文件扩展名并在末尾添加斜杠。但是,我想从根文件夹 htaccess 规则中排除子目录 /sub-dir/ 。我尝试将另一个 htaccess 添加到 /sub-dir/ 文件夹并将RewriteOptions inherit
orRewriteEngine 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]
任何建议都受到高度赞赏。
谢谢