【问题标题】:htaccess redirect all requestes to index.php except sub folderhtaccess 将所有请求重定向到 index.php,子文件夹除外
【发布时间】:2012-12-07 11:49:06
【问题描述】:

我在域的根目录安装了一个 CMS,并使用以下 htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

这会处理友好的 url 以将所有内容重定向到 index.php。我的问题是我有一个包含另一个 cms 的子文件夹。我需要将子文件夹的请求重定向到正确的文件夹而不是 index.php。

我尝试了以下方法,但似乎不起作用

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(sub-folder)
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

谁能帮忙?

谢谢

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting apache2


    【解决方案1】:

    您应该正确验证请求 uri 是否与子文件夹匹配

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !/subfolder
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    

    无论如何,前两个rewritecond的意思是:如果请求文件名不是文件或目录。这意味着如果您引用的文件在子文件夹中并且子文件夹在您的 docroot 中,则您无需执行任何操作。

    如果仍然无法正常工作,启用日志可以帮助您:

    RewriteLog "/web/logs/mywebsite.rewrite.log"
    RewriteLogLevel 9
    RewriteEngine On
    

    在生产环境中避免这种登录

    对 Level 使用较高的值会显着降低 Apache 服务器的速度!使用级别大于 2 的重写日志文件仅用于调试!

    【讨论】:

      猜你喜欢
      • 2015-03-21
      • 2016-11-30
      • 2013-10-26
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多