问题
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