IIS 7 Can you rewrite a rewrite - iis

I am trying to get something like this working with iis 7 microsoft rewrite plugin.
if user requests...
/author/bob/ - show bobs author page
if user requests ...
/author/bob/rss - show authors rss page by rewriting it to
/author/bob/?rss
however i want to to do it in a generic way for urls that end with /rss e.g. for 2 path parts...
<rule name="rss 2 dir listing" stopProcessing="false">
<match url="^([^/]+)/([^/]+)/rss$" />
<action type="Rewrite" url="/{R:1}/{R:2}/?rss" appendQueryString="true" />
</rule>
so the above rule would have to go through to another rewrite rule i.e the one that maps to the author page.
but it looks like this now tries to may to a static directory i.e. the 404 error output is
Requested URL http://site.l:80/author/bob/?rss
Physical Path C:\Users\Workspace\site.l\author\bob\
so its looking for a static directory but you can see its rewritten in to ?rss and trying the url http://site.l:80/author/bob/?rss in the browser works
I am using iis with railo tomcat so it could be a connector issue
Here is the current author rule with the rss incorporated ideally i want to remove adding rss per rule and use generic rules above.
<rule name="author item" stopProcessing="false">
<match url="^author/([a-zA-Z0-9-]+)/(rss)?$" />
<action type="Rewrite" url="/index.cfm?event=AuthorController.getItem&name={R:1}&{R:2}" appendQueryString="true" />
</rule>

Related

IIS UrlRewrite for reverse proxy only working if folder exists on primary website

I've got two websites on the same box and I want to reverse proxy a folder on one to the other. It is only working for directories if I create the directory on the parent website.
so i want http://site/odata/Books
to go to
http://myodatasite/odata/Books
Pretty straightforward, but it is not working unless I go to wwwroot/site and create the /odata/Books folders there. If I do this, the rewrite works. If I call /odata/Authors, again it will 404 unless I create an Authors folder.
It seems like I need to have a wilcard mapping in place in IIS or something else is causing the rewrite to fail. I have tried adding a wildcard mapping pointing to aspnet_isapi and had no changes, possibly because of integrated mode but I haven't found anything that is helpful online yet for this.
Does anyone know why my rewrite is not working for directories but a redirect works fine?
<rewrite>
<rules>
<!-- Does Not Work unless folders exist on current site! -->
<rule name="OdataRoutes" stopProcessing="true">
<match url="^odata/(.*)" />
<action type="Rewrite" url="http://myodatasite/odata/{R:1}" />
</rule>
<!-- Works -->
<rule name="OdataRoutes2" stopProcessing="true">
<match url="odata2/(.*)" />
<action type="Redirect" url="http://myodatasite/odata/{R:1}" />
</rule>
<!-- Works -->
<rule name="OdataRoutes3" stopProcessing="true">
<match url="(.*)\.odata" />
<action type="Rewrite" url="http://myodatasite/odata/{R:1}" />
</rule>
</rewrite>
Looks like it wasn't the mappings at all. Turning on Failed request tracing and monitoring the successful request and the failed request, it seemed the directory rewrite was being passed from ARR to the MvcHandler. Not sure why the redirect wasnt and the rewrite was, but after seeing that, the fix was pretty easy.
routes.IgnoreRoute("odata/{*pathInfo}");

IIS URL Redirect failing

I need to redirect URLs of the form:
http://server1.name.here/path1/path2/?num=123456
to:
http://server2.name.here/path3/path2/?num=123456
using the IIS URL Rewrite Module 2.0 on IIS 8.5. I've used a DNS alias to handle the server name redirection.
I've been using the user interface to configure the path rewrite but despite trying several variations and extensive research I cannot get my rewrite to work, which is slightly embarrassing as I feel this should be a simple rewrite. The web.config produced by the URL rewite user interface is:
<rewrite>
<rules>
<rule name="path rewrite" patternSyntax="ECMAScript" stopProcessing="false">
<match url="path1/path2/" ignoreCase="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="num=[0-9]+" />
</conditions>
<action type="Rewrite" url="path3/path2/" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
When I try to open server1.name.here/path1/path2/?num=123456 I get a "403 - Forbidden: Access is denied." and the logs show no evidence that my URL is being rewritten or even flagged by the rewrite rule.
I'm sure I'm missing something obvious, can anyone enlighten me as to what I've got wrong?
Many Thanks Eden

What's the proper method to tweak the URL in IIS or in web.config?

I am using Sitefinity CMS, one of my website sections for my pages is showing up in the URL and it makes the URLs look not very friendly, the section name is 'Footer' and the URL looks like this:
http://www.domain.com/footer/press-releases/first-press-release
How do I change/rewrite this URL in IIS or in web.config and remove the 'footer/' only so the URL looks like:
http://www.domain.com/press-releases/first-press-release
Thank you
In Sitefinity 6.3 and above you can edit the URL structure:
http://www.sitefinity.com/developer-network/forums/general-discussions-/sitefinity-6-3-released
This means, that even if the page is under the Footer group page, then you can remove the /footer/ from the URL of the page.
Just edit the Title and Properties and click on Change next to the URL.
I'd like to suggest you take a look at the IIS module URL Rewrite
http://www.iis.net/downloads/microsoft/url-rewrite
It would allow you to add rules allowing the 301 redirect you appear to need.
With the module installed you could add this to your web.config file:
<rewrite>
<rules>
<rule name="PressRelease" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^first-press-release$" />
<conditions>
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/press-releases/first-press-release" appendQueryString="false" />
</rule>
</rewrite>

URL Rewriting IIS 7 Querystring Issue

I'm running a legacy website which has a tonne of 301 redirects on it. In an effort to make my life simpler, I switched them from doing manual 301 redirects in IIS to using the url rewriting module and a rewrite map, which I can generate from the database.
Unfortunately I've now hit a snag, in that some of their urls come with querystrings (from Google's adwords), and these invariably 404 (because they don't match the urls in my rewrite map).
Is there a way around this, or do I have to go back to manually doing the 301s?
For the record: we're using IIS7
Code samples:
url: http://mydomain.com/widgets/?gclid=[google code]
Rewrite Rule:
<rule name="Rewrite rule1 for News301Redirects" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{News301Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{C:1}" appendQueryString="false" />
</rule>
Map Line:
<add key="/widgets/" value="/widgets.asp" />
Well, the answer proved to be depressingly simple - just an absolute pig to find.
Instead of using REQUEST_URI (which gets the whole requested URL, including the querystring) I've switched to using URL (which just gets the URL without the querystring) and that seems to have utterly resolved my problems.

IIS7 rewrite for REST not working

I have a REST service and am trying to remove the .svc - a common task/problem.
The application on the server is in a virtual directory under the default website (not sure if this is important)
I have installed the IIS Rewrite Module and have tried to create a rewrite rule for this.
http://blah.me.com/here/thingys/get?id=1111
to rewrite to this:
http://blah.me.com/service.svc/thingys/get?id=1111
In my web.conf the following is created:
<rewrite>
<rules>
<rule name="GEAPI /here/ to /service.svc/">
<match url="^(.*?)/here/(.*)$" />
<action type="Rewrite" url="{R:1}/service.svc/{R:2}" />
</rule>
</rules>
</rewrite>
In the GUI the regular expression does test correctly.
However - when I run this in a browser on the server, it gives the following 404 error:
Error Code 0x80070002
Requested URL http://blah.me.com:80/here/thingys/get?id=1111
Physical Path C:\MyApp\here\thingys\get
C:\Myapp is the correct physical directory the virtual directory in IIS is pointing to.
Is there something I am missing here ? I have tried creating this rule under both the default website and the app, both separately and together.
Big thanks
P
You could use this:
<rewrite>
<rules>
<rule name="GEAPI /here/ to /service.svc/">
<match url="^(.*)here(/.+)" />
<action type="Rewrite" url="{R:1}service.svc{R:2}" />
</rule>
</rules>
</rewrite>
IIS will only give you the part of the URI that's after http://blah.me.com/

Resources