Apache rewrite third directory depth to first directory depth

耗尽温柔 提交于 2020-01-06 08:40:10

问题


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]

回答1:


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] 


来源:https://stackoverflow.com/questions/8253779/apache-rewrite-third-directory-depth-to-first-directory-depth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!