Apache重写异常,不包括特定目录

Apache重写异常,不包括特定目录,apache,mod-rewrite,Apache,Mod Rewrite,设置 我的设置是为两个或多个具有相似结构但内容不同的站点共享资源。例如 http://localhost/site1/ http://localhost/site2/ 有两种类型的重写,CMS内容(几乎只是回显到页面上的内容)和特殊模块(例如博客软件模块),其中我有软件,用于更具体地处理数据库中的内容 因此,博客的第一个重写规则确保博客模块处理博客请求 http://localhost/site1/blog/* http://localhost/site2/blog/* …使用位于的博客模块软件

设置

我的设置是为两个或多个具有相似结构但内容不同的站点共享资源。例如

http://localhost/site1/

http://localhost/site2/

有两种类型的重写,CMS内容(几乎只是回显到页面上的内容)和特殊模块(例如博客软件模块),其中我有软件,用于更具体地处理数据库中的内容

因此,博客的第一个重写规则确保博客模块处理博客请求

http://localhost/site1/blog/*

http://localhost/site2/blog/*

…使用位于的博客模块软件

http://localhost/blog/

CMS重写规则旨在处理非特定模块请求

http://localhost/site1/*

http://localhost/site2/my_page.html*

…使用位于

http://localhost/rewrite.php

问题

博客模块和CMS模块重写冲突。我尝试使用以下规则创建一个例外。这是我的密码

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.js$
RewriteRule .*/blog(.+) blog$1 [QSA]
RewriteRule !.*/(admin|blog|forums)(.+)$ rewrite.php
最后一条规则实际上不起作用。如果我访问

http://localhost/site1/blog/*

http://localhost/site2/blog/*

…任何站点的任何博客(或管理员或论坛)URL仍在重写,以便与localhost/rewrite.php一起使用

那么我如何调整最后一条规则以满足以下条件呢

1.)第一个目录(localhost/site1/blog中的site1或site2)保持动态,因此如果需要,我可以添加第三个站点,而无需出于任何原因重新调整代码

2.)博客(或管理员或论坛)索引(如blog/、论坛/、管理员/)由其自己的模块以及这些目录(如admin/1、admin/test.html)内的任何内容处理,而不考虑HTTP代码、200、404等

3.)不在最后一条规则的例外列表中的任何URL都由rewrite.php处理(不管HTTP代码、200、404等)

4.)localhost/site1/blog/不由rewrite.php处理,localhost/site1/random_路径不由blog模块rewrite处理


我很乐意尽快回复,并进一步澄清。

多亏有人写了一篇有意义的文章,我修改了它,效果很好

请注意,如果有人决定使用此代码,那么这些条件显然只在模块(管理员、博客、论坛)的特定重写规则之后起作用,而在CMS rewrite.php规则之前起作用

我很乐意接受任何积极的批评

RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css|js|zip)$

RewriteRule .*/admin(.+) admin$1 [QSA]
RewriteRule .*/blog(.+) blog$1 [QSA]
RewriteRule .*/forums(.+) forums$1 [QSA]

#individual...
RewriteCond %{REQUEST_URI} !.*/admin
RewriteCond %{REQUEST_URI} !.*/blog
RewriteCond %{REQUEST_URI} !.*/forums

#condensed...
RewriteCond %{REQUEST_URI} !.*/(admin|blog|forums)

RewriteRule !\.(css|js|zip)$ rewrite.php