Joh*_*ohn 6 apache mod-rewrite
安装程序
我的设置是为两个或多个具有相似结构但不同内容的站点共享资源.在例子中......
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*
...使用位于...的CMS重写软件
http:// localhost/rewrite.php
问题
博客模块和CMS模块重写是冲突的.我试图使用以下规则进行例外处理.这是我的代码......
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.js$
RewriteRule .*/blog(.+) blog$1 [QSA]
RewriteRule !.*/(admin|blog|forums)(.+)$ rewrite.php
Run Code Online (Sandbox Code Playgroud)
最后一条规则实际上不起作用.使用此代码,如果我访问..
http:// localhost/site1/blog/*
http:// localhost/site2/blog/*
...任何网站的任何博客(或管理员或论坛)URL仍在被重写以与localhost/rewrite.php一起使用.
那么如何调整最后一条规则以满足以下条件呢...
1.)第一个目录(localhost/site1/blog中的site1或site2)仍然是动态的,所以如果我愿意,我可以添加第三个站点,而不必因为任何原因重新调整代码.
2.)博客(或管理员或论坛)索引(例如blog /,forums /,admin /)由他们自己的模块以及这些目录中的任何内容处理(例如admin/1,admin/test.html)无论HTTP代码,200,404等.
3.)任何不在最后一个规则的例外列表中的URL由rewrite.php处理(无论HTTP代码,200,404等).
4.)localhost/site1/blog /不由rewrite.php处理,localhost/site1/random_path不由blog模块重写处理.
我很乐意快速回复任何进一步的澄清.
感谢早期的RewriteCond,有人写道,这是有道理的,我改编了它并且效果很好!
请注意,如果有人决定使用此代码,条件显然仅在模块(管理员,博客,论坛)的特定重写规则之后才能使用,尽管在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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5918 次 |
最近记录: |