Apache的重写第三目录深度为第一个目录深度 [英] Apache rewrite third directory depth to first directory depth

查看:148
本文介绍了Apache的重写第三目录深度为第一个目录深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有设在这里两个网站的资源...

 本地主机/ index.php文件/ *重写程序* /
本地主机/图像/
本地主机/脚本/

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

 本地主机/ SITE1 /
本地主机/站点2 /

我要重写...

 本地主机/ SITE1 /图像/
本地主机/站点2 /图片/
本地主机/ SITE1 /脚本/
本地主机/站点2 /脚本/

...到...

 本地主机/图像/ SITE1 /
本地主机/图像/站点2 /
本地主机/脚本/ SITE1 /
本地主机/脚本/站点2 /

有没有一种方法,使站点1和站点2动态变量(这样我就不必手动添加异常或如果我添加在将来更多的网站规则),将用这种方式重写?

本规则重写的目录,我希望能够和访问文件,而不仅仅是指数...

 重写规则。* \\ /脚本\\ / $脚本\\ / $ 1 [L]


解决方案

有关,一旦Apache文档是有益的!

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

  RewriteEngine叙述上
重写规则。* \\ /脚本(+)脚本$ 1 [QSA]

I have resources for two websites located here...

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

Then I have the two sites...

localhost/site1/
localhost/site2/

I want to rewrite...

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

...to...

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

Is there a way to make "site1" and "site2" a dynamic variable (so that I don't have to manually add an exception or rule if I add more sites in the future) that will rewrite in this manner?

This rule REWRITES the directory, I want to be able to access the files AS WELL, not just the index...

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

解决方案

For once the Apache documentation was useful!

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

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

这篇关于Apache的重写第三目录深度为第一个目录深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆