【问题标题】:How do I prevent .htaccess rewrite from affecting folders?如何防止 .htaccess 重写影响文件夹?
【发布时间】:2012-06-17 08:15:18
【问题描述】:

这是我当前的 .htaccess:

RewriteEngine on
RewriteBase /cp/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule ^(?!\s*$).* $0.php [L]

这会影响同一目录中的文件夹。 这是一个示例文件夹目录:

  • ..
  • css/
  • 图片/
  • 文件名.php

如果我输入url: WEBSITE.com/filename,会拉取filename.php,但是当我输入WEBSITE.com/css时,会拉取WEBSITE.com/css/.php。

我不希望 .htaccess 影响子目录,也不希望将单独的 .htaccess 文件放在每个文件夹中。

【问题讨论】:

  • 添加 RewriteCond %{REQUEST_FILENAME} !-d

标签: .htaccess directory rewrite


【解决方案1】:

感谢 jasssonpet。

我以为我应该替换 add RewriteCond %{REQUEST_FILENAME} !-f 而不是添加 add RewriteCond %{REQUEST_FILENAME} !-d

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 2015-09-27
    • 2011-09-13
    相关资源
    最近更新 更多