【问题标题】:Apache Mod-Rewrite rule to skip sub directoryApache Mod-Rewrite 规则跳过子目录
【发布时间】:2012-03-23 09:14:07
【问题描述】:

我在一个网站的根目录中有一个应用程序,它有自己的 apache2 mod-rewrite 规则,例如

   RewriteRule ^/([^/]*)/([^/]*)/$ /index.php?page=$1&var1=$2
   RewriteRule ^/([^/]*)/$ /index.php?page=$1

很好,但现在我想将 Wordpress 安装在子目录 /blog 中。 Wordpress 当然在 .htacess 文件中有自己的重写语句,它会为博客以不同的方式重写 url。

如何让根 .htaccess 文件跳过 /blog/ 目录并允许本地 .htaccess mod-rewrite 在浏览博客目录时仍然有效。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    你只是在你的第一个 htaccess 中做一个否定

    RewriteCond %{REQUEST_FILENAME} !^/blog/.*$
    

    这应该可以 - 希望!作为规则的前提

    【讨论】:

      【解决方案2】:

      在 DOCUMENT_ROOT 下的 .htaccess 中使用此代码:

      RewriteRule ^blog/ - [L]
      
      RewriteRule ^/([^/]*)/([^/]*)/$ index.php?page=$1&var1=$2 [L,QSA]
      RewriteRule ^/([^/]*)/$ index.php?page=$1 [L,QSA]
      

      【讨论】:

      • 这不会忽略博客目录中wordpress的规则吗?
      • 不,它不会,因为这个忽略只会在当前的 .htaccess 中有效
      猜你喜欢
      • 1970-01-01
      • 2019-09-13
      • 2011-07-20
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多