限制RewriteRule以忽略某些文件夹

时间:2017-01-16 22:33:32

标签: .htaccess mod-rewrite url-rewriting

我的网站根目录中有一个基本的重写规则,位于.htaccess文件中:

<IfModule mod_rewrite.c>

    # http://www.generateit.net/mod-rewrite/index.php

    # Tell PHP that the mod_rewrite module is ENABLED.
    SetEnv HTTP_MOD_REWRITE On

    RewriteEngine on

    RewriteRule ^([^/]*)/$              category.php?cat=$1 [L]
    RewriteRule ^([^/]*)/([^/]*)/$      post.php?cat=$1&post=$2 [L]
    RewriteRule ^blog-([^/]*).php$      default.php?page=$1 [L]

</IfModule>

我有两个托管在同一文件夹结构上的网站:

DIR: example2.com
file: category.php
file: default.php
file: post.php

因此重写规则将重定向,例如。

example.com/post.php?cat=general-ledger&post=gl-journals-volumes

为:

example.com/general-ledger/gl-journals-volumes /

但是,我已经在example2上的一个名为ddc的文件夹中安装了Wordpress,但是当我访问时:

example2.com/ddc/wp-admin/user /

我无法查看它,因为系统认为它正在尝试查看重写的页面。

有什么方法可以阻止重写规则触发特定目录?

我试过了:

RewriteCond %{REQUEST_URI} !^/(example2.com|ddc)/?(.*)$ [NC]

但它没有任何区别。此外,当我尝试访问该文件夹时,错误日志会显示此信息:

  

[Mon Jan 16 22:39:53.365334 2017] [autoindex:error] [pid 28997]   [client my_ip_address_here:53652] AH01276:无法提供目录服务   /home/oracle36/public_html/example2.com/ddc/wp-admin/user/:否   匹配找到的DirectoryIndex(default.php)和服务器生成的   Options指令禁止的目录索引

1 个答案:

答案 0 :(得分:1)

您的重写规则不是问题。它们仅影响具有一个或两个级别目录的URL。您的问题是您没有将index.php设置为目录索引,因此Apache无法从WordPress目录中提供服务。将其添加到.htaccess:

DirectoryIndex default.php index.php

我正在添加default.php,因为错误消息显示您已经设置了该设置,然后将index.php作为另一个选项添加到它,以支持WordPress。你可以删除你的RewriteCond。

相关问题