【问题标题】:htaccess only in root folderhtaccess 仅在根文件夹中
【发布时间】:2012-01-13 09:13:14
【问题描述】:

我一直在寻找答案,但没有找到。我在根文件中有 .htaccess,它将 /loremipsum/ 重定向到 index.php?url=loremipsum,但是,它也想在子目录中工作。我有很多,因此将 .htaccess 文件放入每个人都会很痛苦。有没有办法让它只在根文件夹中工作?

【问题讨论】:

  • 你使用的规则是什么?
  • Options -MultiViews +FollowSymLinksRewriteEngine OnRewriteRule ^(.+)/$ index.php?url=$1 [L]
  • 也许将index.php 更改为/index.php?不确定在子目录中工作是什么意思。
  • 我的意思是,如果我去 myaddres.com 这是停在同一台服务器上的域,我什至无法访问 index.php,因为 .htaccess 在根文件夹中

标签: .htaccess mod-rewrite redirect


【解决方案1】:

如果您添加此规则,它将仅适用于不存在的文件和文件夹

Options -MultiViews +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?url=$1 [L]

【讨论】:

    【解决方案2】:

    要使您的重定向规则仅在根目录中有效,请使用此基于 negative lokahead 的代码:

    Options -MultiViews +FollowSymLinks 
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule ^([^/]*)(?!/.*)$ index.php?url=$1 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-16
      • 2016-10-29
      • 2011-09-13
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      相关资源
      最近更新 更多