IIS Throwing HTTP 500 for rewrite rules - iis

When I put my web.config into any folder/main directory it seems to be throwing the HTTP error code: 500--unfortuenly I don't have access to the logs so I can't see why, so surely it's down to my web.config - I've never used IIS before but I'm trying to re-route all requests to a file called 'api.php', here's my web.config file.
<rewrite>
<rules>
<rule name="rule 1Q">
<match url="^/.*" />
<action type="Rewrite" url="/api.php" />
</rule>
</rules>
</rewrite>
Apache equivalent:
RewriteEngine on
RewriteRule ^/.* /api.php
Any help is greatly appreciated.

This is not an exact answer because I am not sure of your server variables but here is something that might be useful to you. Here. This walks through the IIS set up for version 7 and it has some basic concepts. There is rewrite module/tool that could help but I haven't used it. And another document here...Shows the GUI interface like the first link and is in 7.5.
Again not specific solutions but hopeful you have some server gurus there that can help you at least get the IIS settings right (or at least not sound dumb if you have to communicate something specific to them) if this is a first time IIS Isapi venture for you.

Related

web.config 301s for all files but one

I'm trying to set up 301s for a site which will bounce all old pages to the homepage (it was a large site that is now a single page).
The server's Windows based, however, so no htaccess fun for me.
Could anybody assist with producing a web.config file that redirects everything to the homepage via 301s?
This may work:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="301 Redirect Everything To Home" stopProcessing="true">
<match url=".+" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
But is will redirect everything, including images, include files etc.
Could you explain your motive for this as generally it's a bad move. It causes a poor user experience, robots don't like it, and nothing knows if a page is really missing or not.
I suggest you to try "IsapiRewrite" 3rd party module/DLL
ISAPI_Rewrite is a powerful regular-expressions-based URL rewriter for
IIS. It is compatible with Apache mod_rewrite making it possible to
move configurations from Apache to IIS and vice versa just by copying
.htaccess files (please see this compatibility chart). It is used for
search engine optimization, to proxy another server's content, stop
hotlinking or strengthen server security.

Forwarding NTLM credentials from IIS with ARR and URL Rewrite

Thanks in advance for your help.
In my environment, I configured IIS to act as a reverse proxy and forward requests to certain paths to an application server on another host. In order to do this, I used Application Request Routing (ARR) and URL Rewrite modules, I create my rule and everything's working fine.
IIS is responsible to authenticate clients using NTLM, so my question is: is it possible to pass the authentication credentials (at least the username) to my application server after authenticating the user?
I tried to do this adding a custom header to my requests, writing a rule like this:
<rule name="ForwardToApplicationServer">
<match url=".*" />
<serverVariables>
<set name="HTTP_AUTH_USER" value="{AUTH_USER}" />
</serverVariables>
<action type="Rewrite" url="http://myappserver/myapp/{R:0}" logRewrittenUrl="true" />
</rule>
But it doesn't work: when I read it on my application my header is alwasy empty. I also tried with and but none of these worked.
So, what am I doing wrong? Should I use another server variable? Am I missing something?
More in general: is it possible to do what i'd like to do?
Again, thanks in advance for your help, and please forgive me if I'm asking something obvious but I'm new to using IIS and I couldn't find anything that helped me.
http://weblogs.asp.net/owscott/an-intro-to-iis-url-rewrite-plus-redirecting-urls-to-www-web-pro-week-8-of-52
{REMOTE_USER}, {LOGON_USER} & {AUTH_USER} do not work with URL-REWRITE, ...
You can use www.isapirewrite.com which runs later in the stack and has a handle on the auth data.

Custom URL Rewriting in Classic ASP

I have been trying to rewrite the URL in classic ASP. I am currently using IIS 7.5. I tried to use the URL Rewrite plugin which converts the following link:
http://blog.johnavis.com/blog/default.asp?id=19
into something like this:
blog.johnavis.com/19/
blog.johnavis.com/id/19/
blog.johnavis.com/blog/default/19
blog.johnavis.com/blog/default/id/19
I want to convert into something like this:
http://blog.johnavis.com/blog/myblog/
Can that be achieved? Any help would be appreciated.
Basically all the rewrite module does is to edit your web.config file. You're probably better off editing the file yourself. You'll find that it has created a section called rewrite, add the following rule
<rewrite>
<rules>
<rule name="My Blog">
<match url="blog/myblog/" />
<action type="Rewrite" url="blog/default.asp?id=19" />
</rule>
</rules>
</rewrite>
You can achieve this by creating URL rewrite rule in IIS Manager by defining a pattern. Use the following links to learn about that.
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-video-walkthrough
Hope this helps...

ARR/URL Rewriter within a .net Web API application

I have two applications. One of which is going to handle authentication across a range of products. Because of this, from each one I want to rewrite a URL from each individual website to our "authentication" project. It would look something like this.
http://www.mywebsite.com/api/profile/login -> http://www.myauthentication.com/api/profile/login.
So essentially pushing the request cross domain.
For this I have setup ARR and URL Rewriting in IIS. However I can't seem to get it to work, and I have a feeling URL Rewriting is not running on requests that would normally cause a 404. I think this because on a REDIRECT request (301 redirect), the config works perfectly. When I use a rewrite, I get a generic 404 page.
The rules configuration looks as per below :
<rules>
<rule name="Route the requests for the Profile API." enabled="true" stopProcessing="true">
<match url="^profiles/(.*)" />
<action type="Rewrite" url="http://authentication.local/api/profiles/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
It should be noted that I am using the WebAPI, not MVC, which I'm not sure if that is causing issues or not. Because the redirect works but not the rewrite, I'm sure I've got everything installed OK in IIS.
For ARR, I have simply ticked "Enable Proxy" but I am unsure if I need to do anything else.
I managed to solve this by adding an ignore route for ARR.
RouteTable.Routes.IgnoreRoute("api/profiles/{*pathInfo}");

IIS Url Rewriter rewrite fails but redirect works flawlessly

I have to set up a couple of apps on a new intranet server (Win 2008 R2 Standard SP1). I have been having some difficulty with a URL Rewriter rule. I had a similar rule working great on my local IIS (Win 7). The rule is designed to create a reverse proxy for a web service that enables jQuery AJAX requests from the client to avoid XSS.
The rule is as below and if I use this as is, and type an example URL into the browser:
http://srv01.domain.com/serviceproxy/workflow/Users/GetUsers?q=smith&max=10
I get a 404 response from the server. If I change the type to "Redirect" I get the response from the server expected (but obviously this will void my attempt to avoid XSS).
<rewrite>
<rules>
<rule name="Reverse Proxy - WCF Service" stopProcessing="true">
<match url="serviceproxy/workflow/(.+)" />
<action type="Rewrite" url="http://srv01.domain.com/WorkflowService/{R:1}" />
</rule>
</rules>
</rewrite>
Any ideas what might be missing from the server configuration? Is it a security setting somewhere that needs to be configured to allow the rewrite to occur?
I found my issue. I didn't have Application Request Routing installed on this server. Either I forgot installing it on my other server or it was already on there for another reason.
Found this article that helped me resolve it.
http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
Had a similar issue on Windows 2008, IIS 7.5
The problem was that the app pool was in integrated mode. that caused issues with the rewrite.
Redirect was always ok, but rewrite always failed.
changed the app pool to classic mode and problem solved (at least for now).
a better solution might be http://forums.iis.net/t/1200671.aspx?ARR+URl+Rewrite+is+not+working+for+external+servers
right at the end. but i havent tried it.

Resources