I'm trying to setup a medi proxy to prevent people accessing files which have an expiry date on. To do this, I want to create a global media handler. So my idea was to add a URL rewrite rule to point all media to my handler as follows:
However, this doesn't seem to work. It never gets hit. The weird thing is, if I convert this to a redirect instead of a rewrite by adding the redirect="Application" attribute to it, it fires.
Anybody got any ideas why original rewrite isn't firing?
Okay, I'm speaking from ignorance because I haven't done this myself but I can imagine a couple things that might be relevant...
Set the app pool to send all requests (or at least all media requests) through .net
Try with the iis rewriter instead of urlrewriter.net that's in umbraco
If #2 works you have a solution. If it doesn't, it isn't umbraco's fault, look elsewhere
If #2 works and you want to look at it further, consider this question: is there any need for umbraco to handle this request at all since the /media folders are not 'virtual' at all. Thus it seems like umbraco's built-in urlrewriter.net handler won't be used for a simple rewrite
I can never figure out which RegEx features are available for the UrlRewriter, i.e., normally you'd have to escape those forward-slashes... and I seem to remember not having to escape the dot in some cases, either - which would again mean that the dot you're using in the "normal" way (as anything but a newline) probably shouldn't work, no?
Be good to know what the real problem is when you solve it...
I always use the IIS UrlRewrite plugin, just because it's got more features and works all the time ;-) It is weird that the rule works when using a redirect instead of rewrite.
Just wanted to mention that I'd use this instead with IIS UrlRewrite:
^/media/([0-9]+)/.+$
/MediaHandler.ashx?id={R:1}&url={R:0}
Btw, I'm not sure what you're doing with the id, because it's not the media id (as you'll probably know...)
I couldn't figure out why it didn't work (did dougs suggestions, though couldn't get IIS rewrites working in IIS Express either), so ended up creating a HttpHandler against the path "/media/*" instead, this then triggers for every media request which I then just run the regex internally to parse the url.
@kipusoep I parse the property id to do a lookup and fetch the media id. Doing it in the regex just means I wouldn't have had to parse it, instead it would just have been passed in on the querystring.
I was stumble upon this thread today trying to accomplish almost the same thing: prevent people accessing files. I used the following URL rewrite to point all media, except images, to a generic handler:
But unless adding redirect="Application" attribute it didn´t work. So I installed the IIS Rewrite module and added the following rewrite rule in Web.config ...
Unless I didn´t do it wrong, IIS is still the way to go. Someone else who got any insights to this?
Update:
Watching Shannon at the Umbraco UK festival 2015, talking about Umbraco V8 and beyond. The UrlRewriting.NET will not be shipped in Umbraco anymore due to bugs and inactivity. He also recommend IIS Rewriting. So I guess that ties it all together. :)
using IIS Rewriting i want to rewrite media file for all content pages and rewrite as //cdn.mydomain.com...
because these images get from cdn ..i try your pattern but its not work please help me to do so
URL rewriting media
Hey Guys,
I'm trying to setup a medi proxy to prevent people accessing files which have an expiry date on. To do this, I want to create a global media handler. So my idea was to add a URL rewrite rule to point all media to my handler as follows:
However, this doesn't seem to work. It never gets hit. The weird thing is, if I convert this to a redirect instead of a rewrite by adding the redirect="Application" attribute to it, it fires.
Anybody got any ideas why original rewrite isn't firing?
Okay, I'm speaking from ignorance because I haven't done this myself but I can imagine a couple things that might be relevant...
Keep us posted.
cheers,
doug.
Hi Matt,
I can never figure out which RegEx features are available for the UrlRewriter, i.e., normally you'd have to escape those forward-slashes... and I seem to remember not having to escape the dot in some cases, either - which would again mean that the dot you're using in the "normal" way (as anything but a newline) probably shouldn't work, no?
Be good to know what the real problem is when you solve it...
/Chriztian
I always use the IIS UrlRewrite plugin, just because it's got more features and works all the time ;-)
It is weird that the rule works when using a redirect instead of rewrite.
Just wanted to mention that I'd use this instead with IIS UrlRewrite:
^/media/([0-9]+)/.+$
/MediaHandler.ashx?id={R:1}&url={R:0}
Btw, I'm not sure what you're doing with the id, because it's not the media id (as you'll probably know...)
Hey Guys,
I couldn't figure out why it didn't work (did dougs suggestions, though couldn't get IIS rewrites working in IIS Express either), so ended up creating a HttpHandler against the path "/media/*" instead, this then triggers for every media request which I then just run the regex internally to parse the url.
@kipusoep I parse the property id to do a lookup and fetch the media id. Doing it in the regex just means I wouldn't have had to parse it, instead it would just have been passed in on the querystring.
Thanks for the suggestion though guys.
Matt
Ah that's what I thought when typing my comment :-)
You need to install the iis rewrite package for IIS, it isn't installed by default in either IIS or IIS Express.
But glad you got a solution in the end!
cheers,
doug.
Hi guys,
a long time has passed since this topic has been started.
Is there a way to make this in Umbraco 7? Or is it still only using IIS? Are there any new insights?
In my specific case, users want to be able to put a custom URL for each media node.
Any ideas how I can solve this?
Best,
Sören
Hello,
I was stumble upon this thread today trying to accomplish almost the same thing: prevent people accessing files. I used the following URL rewrite to point all media, except images, to a generic handler:
But unless adding redirect="Application" attribute it didn´t work. So I installed the IIS Rewrite module and added the following rewrite rule in Web.config ...
... which worked as expected.
Unless I didn´t do it wrong, IIS is still the way to go. Someone else who got any insights to this?
Update: Watching Shannon at the Umbraco UK festival 2015, talking about Umbraco V8 and beyond. The UrlRewriting.NET will not be shipped in Umbraco anymore due to bugs and inactivity. He also recommend IIS Rewriting. So I guess that ties it all together. :)
Hello Martin
using IIS Rewriting i want to rewrite media file for all content pages and rewrite as //cdn.mydomain.com... because these images get from cdn ..i try your pattern but its not work please help me to do so
is working on a reply...