Apache将第三个目录深度重写为第一个目录深度

时间:2011-11-24 08:00:42

标签: apache mod-rewrite

我有两个位于此处的网站的资源......

localhost/index.php /* rewrite handler */
localhost/images/
localhost/scripts/

然后我有两个网站......

localhost/site1/
localhost/site2/

我想改写......

localhost/site1/images/
localhost/site2/images/
localhost/site1/scripts/
localhost/site2/scripts/

...到...

localhost/images/site1/
localhost/images/site2/
localhost/scripts/site1/
localhost/scripts/site2/

有没有办法让“site1”和“site2”成为一个动态变量(这样我不必手动添加异常或规则,如果我将来添加更多的网站)将以这种方式重写?

此规则REWRITES目录,我希望能够访问文件AS WELL,而不仅仅是索引......

RewriteRule .*\/scripts\/$ scripts\/$1 [L]

1 个答案:

答案 0 :(得分:0)

一旦Apache文档很有用!

http://httpd.apache.org/docs/2.3/rewrite/flags.html#flag_qsa

RewriteEngine on
RewriteRule .*\/scripts(.+) scripts$1 [QSA]