开发者

Rewrite URL to an unknown filename

I want开发者_如何转开发 to add a prefix to URLs as they come through mod_rewrite. I think this is simpler to show in an example than to explain.

Eg, '/my-filename' gets rewritten to '([0-9]+).my-filename'

The possible filenames this would match might include 10.my-filename, 55.my-filename, 123.my-filename, etc...

The 'my-filename' part is guaranteed to be unique. Is this possible with mod_rewrite, or will I have to do it in code?

Thanks, Andy.


If I understand what you want, you should look at the RewriteMap directive of mod_rewrite.

It enable you with the rnd format to map a given URL to a random value from a set:

Configuration:

##
##  map.txt 
##

static   www1|www2|www3|www4
dynamic  www5|www6

and rewriting

RewriteMap serveurs rnd:/chemin/vers/fichier/map.txt

RewriteRule ^/(.*\.(png|gif|jpg)) http://${serveurs:static}/$1 [NC,P,L]
RewriteRule ^/(.*) http://${serveurs:dynamic}/$1 [P,L] 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜