IIS7 Rewrite Rule not working - iis-7

I have created a this rule:
<rewrite>
<rules>
<rule name="ImageRedirect" stopProcessing="false">
<match url="^(.*)/(.*)/" />
<action type="Rewrite" url="http://www.lrgimages.com/ImageRewrite.aspx?=img={R:2}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
I keep getting a 404.0 message like the rule is not working or IIS is not picking it up. In the test parttern section for the rule, the pattern tests fine. If I go directly to the http://www.lrgimages.com/ImageRewrite.aspx that page loades, but not when I try: http://www.lrgimages.com/TestImage
any thoughts?
Update: I figured it out. It does not take into acount hte http://www.DomainName.com when rewriting a url. Redirects work this way since htat is what is is really doing. I am used to other rewrite engines not taking into account the http://www.DomainName.com . Thanks all you lead me in the right direction.

I don't think "/TestImage" matches ^(.*)/(.*)/ ...

Related

Web Config Rewrite/redirect

I am working on an existing project that I did not create.
In the web.config file, there are a number of redirects, setup in the following way:
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/findyourlocalbranch/" value="/find-your-local-branch/" />
</rewriteMap>
</rewriteMaps>
It seems to me that a rewrite rule is being used to do these redirects, but as I said, I did not write this and am not in a position to change this. I am not sure if this is right or wrong.
My problem is that I need to implement the following redirect:
<add key="/need-a-loan/.htm" value="/need-a-loan/" />
but this brings the whole site down - I suspect due to a syntax error in this line.
I suspect the error is the '.' after the '/'
My question is, what can I do about it - there is nothing on the internet that I can find about this.
Basically, I want to redirect this one, specific URL to the given URL???
I can't say whats going on with the map, as without the corresponding rule I'm blind.
But, this rewrite rule will redirect from /need-a-loan/.htm to /need-a-loan/.
<rewrite>
<rules>
<rule name="Need-A-Loan" stopProcessing="true">
<match url="need-a-loan/.htm" />
<action type="Redirect" url="need-a-loan/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Note: doesn't use the map, so you'd remove that entry.
That will give you a 301. If you want a different type, you can adjust the rediectType. E.g. Temporary will give you a 307.

IIS Reverse Proxy

I've got two websites.
XX.XX.XX.XXX:5917 which is a webforms website
And
XX.XX.XX.XXX:5916 which is an mvc website.
Both websites on the same IIS 7 server. I can navigate each website, login, etc.
However, when a user goes to XX.XX.XX.XXX:5917/Report I want the content from XX.XX.XX.XXX:5916/Report to be served up, but the url to remain XX.XX.XX.XXX:5917/Report.
To do this, I'm trying to set up a reverse proxy on the 5917 site to serve up content from 5916.
When I have a redirect rule in place, I can click a link in 5917 to Reports and it will take me to 5916/Reports. This works, but changes the address bar. When I use the Rewrite rule option, absolutely nothing discernible happens. If I screw up the end url in the action bracket then the page will break, so I know it's at least evaluating the rule.
Here is the 'working' redirect rule:
<rule name="Reverse Proxy to Reports" stopProcessing="true">
<match url="\bReport\b" />
<action type="Redirect" url="http://XX.XX.XX.XXX:5916/{R:0}" />
</rule>
Am I missing anything? Where do I go from here?
Try adding this on your XX.XX.XX.XXX:5917 WebForms web.config:
<system.webServer>
...
<rewrite>
...
<rules>
<rule name="ReverseProxyInboundRuleForReports" stopProcessing="true">
<match url="(Report/.*)" />
<action type="Rewrite" url="http://localhost:5916/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
You might need 'Application Request Routing' extension on IIS for it to work though. If so then you can get it from this link:
http://www.iis.net/downloads/microsoft/application-request-routing
You can also read more about the technique on this link:
http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis
Good luck!

Coldfusion 9 & IIS7 URL Rewrite

I'm currently researching how to implement URL Rewriting and was wondering if someone could help shed some light.
Our current url structure is the following..
http://example.com/products.cfm?id=1234
http://example.com/recipes.cfm?id=6789
I would like to configure IIS so that URLs can be rewritten to the following (or similar)
http://example.com/products/1234/product-title-here
http://example.com/recipes/6789/yummy-recipe-ever
How would I go about doing this?
Read through this walk through. The example comes close to what you want (replaced aspx with cfm).
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.cfm?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
Look into Coldbox there is a rewrite.ini and IS7 web.config included
http://wiki.coldbox.org/wiki/URLMappings.cfm
The Coldbox blog shared this link
http://blog.coldbox.org/blog/coldbox-and-url-rewrites-with-iis-7

IIS url rewrite | How to remove directory and extension?

I have been struggling with the following for quite some time now:
Default url:
examplesite.com/folder/about.cshtml
Desired url:
examplesite.com/about
Basically I want to accomplish two things:
1 Remove the file extension with realtively compact code.
2 Remove the folder that houses the about page.
I have found some uncommon rules to achieve all the above, but they mostly contain a lot of redundant code that crashes my site when I test it with IIS 8.0.
So I was hoping someone could share a rule that is compact and fits my needs. Or seperate rules with the same outcome.
Every contribution is much appreciated :)
I'm not certain I entirely understand your needs, but here's something that's at least close. It strips out the first folder and file extension (so examplesite.com/folder/about.cshtml becomes examplesite.com/about and examplesite.com/folder/help/about.cshtml becomes examplesite.com/help/about). If you wanted to strip all folders then just remove the ?.
<rule name="Remove Directory and Extension">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Rewrite" url="{R:2}" />
</rule>
Update:
Ok, I think what you want is a combination of two rules then:
<rules>
<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="folder/{R:0}.cshtml" />
</rule>
</rules>
The first rule makes sure that all requests are to friendly URLs. The second takes the friendly URL and rewrites it to your physical path, where the physical path is folder/[FRIENDLY_PATH].cshtml.

Need help for regex design in system.webServer rewrite rule in web.config

I am redirecting a lot of old pages because of a new webdesign. However I have run into one little issue.
I want to redirect:
www.domainname.com/Default.aspx
But not redirect
www.domainname.com/somesub/Default.aspx
I need it written like this:
<rule name="301 Redirect Default">
<match url="???????" />
<action type="Redirect" url="http://www.domainname.com/index.php" redirectType="Permanent" />
</rule>
Where the questionmarks mark the regex I need.
Can anyone help?
Cheers
How about
<match url="^Default\.aspx" />
Also see e.g. this article regarding IIS rewrite rules.

Resources