【发布时间】:2014-12-17 10:52:21
【问题描述】:
我在我网站的根文件夹中使用以下 htaccess 规则来删除文件扩展名并在末尾添加斜杠。但是,我想从根文件夹 htaccess 规则中排除子目录 /sub-dir/ 。我尝试在 /sub-dir/ 文件夹中添加另一个 htaccess 并将 RewriteOptions inherit 或 RewriteEngine 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]
非常感谢任何建议。
谢谢
【问题讨论】:
-
@Winter 是的。我试过了。我认为它不起作用,因为我的 htaccess 文件上的规则不同。
标签: php apache .htaccess url-redirection trailing-slash