【问题标题】:exclude sub directory from htaccess rules in root folder从根文件夹中的 htaccess 规则中排除子目录
【发布时间】:2014-12-17 10:52:21
【问题描述】:

我在我网站的根文件夹中使用以下 htaccess 规则来删除文件扩展名并在末尾添加斜杠。但是,我想从根文件夹 htaccess 规则中排除子目录 /sub-dir/ 。我尝试在 /sub-dir/ 文件夹中添加另一个 htaccess 并将 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]

非常感谢任何建议。

谢谢

【问题讨论】:

标签: php apache .htaccess url-redirection trailing-slash


【解决方案1】:

您可以尝试在您的子目录中添加一个 htaccess 文件,该文件只有这个:

RewriteEngine On
RewriteRule ^ - [L]

没有任何继承选项。继承意味着您希望父 htaccess 中的规则也与子目录的 htaccess 文件中的任何规则一起应用。这样,您就可以确保重写引擎已打开并制定“什么都不做”的传递规则。

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

RewriteRule ^sub-dir/ - [L]

【讨论】:

  • 我试过 {RewriteEngine On RewriteRule ^ - [L]} 它就像一个魅力。谢谢大家
  • 谢谢,很好:)
  • 第一个不起作用,但第二个起作用。
猜你喜欢
  • 1970-01-01
  • 2015-03-21
  • 2013-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-31
  • 1970-01-01
相关资源
最近更新 更多