I have a strange business case where I need any time a URL is called on my web server that it is re written with the incoming URL.
Example:
Incoming URL
/site/1
URL that it is going to
/innerlink/2
In the browsers URL
/innerline/2 would show /site/1
If you can answer this question or get me to some material that could help me in doing this it would be greatly appreciated. Thanks!
The name of this approach "URL rewriting". In IIS you can achieve it with URL rewrite module.
In your case when you just need to rewrite /site/1 to /innerlink/2 you need to do the following:
Install URL rewrite module for IIS (it might be already installed)
In your web.config you need to add this rewrite rule:
.
<rule name="Laravel5" enabled="true" stopProcessing="true">
<match url="^site/1$" />
<action type="Rewrite" url="/innerlink/2" />
</rule>
And now if you will open in your browser this link {YOUR DOMAIN, IP OR HOSTNAME}/site/1 it will make request to /innerlink/2 (but browser will keep showing /site/1)
P.S. Also you can find some useful rewrite/redirect rules in this article: https://host4asp.net/top-iis-rewrite-rules/
Related
I am trying to figure out what I would need to do for a rewrite rule to apply to tags if possible to append to the source to basically proxy the content of HTTP links.
Looks like google does it for its webmail and I need something similar for my self hosted webmail. I could ingore the Not Fully Secure warning but I want to try to finish it.
Unfortunately I dont remember how I did it in the past and I deleted the old folder to look at the web.config file that would have been in there.
This way I could look for image links with an image of http://example.com/image.png and make it https://example.org/proxy.php?url=http://example.com/image.png and then it would load the same image but now be secure. I have the php setup as needed to do this but now I need to figure out this outbound rewrite.
You can use rules like this.
<rule name="rule" preCondition="ISHTML">
<match filterByTags="A, Img" pattern="(.*)" />
<action type="Rewrite" value="https://example.org/proxy.php?url=http://{HTTP_HOST}{R:1}" />
</rule>
According to the law of image name and php page name, you can customize regular expressions to match the image you want to rewrite and the rewritten url
I've been trying to use the URL Rewrite module to create a rule that looks for any set of two or more forward-slashes in the URL (past the first set) that will redirect the browser to a URL with all sets of multiple forward slashes replaced with just one. Example:
http://myhost.com/abc//def//ghi//jkl//iisstart.png
should redirect to
http://myhost.com/abc/def/ghi/jkl/iisstart.png
I already understand that IIS sees these two URLs as functionally equivalent, but for this public-facing site we want to avoid any chance that crawlers will index URLs with the multiple forward slashes; hence the redirection. So here's the rule I put together:
<rule name="Redirect URLs with Multiple Forward Slashes" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="{URL}" appendQueryString="true" />
<conditions logicalGrouping="MatchAny">
<add input="{UNENCODED_URL}" pattern="//" />
</conditions>
</rule>
I tested this on my local box, and it produced the expected outcome (the redirection). I copied it into a web.config on a development server and tried it out, but it didn't work. I even took the path of making sure the URL Rewrite installation matched the version on the development server (it's 2.0, and upgrading would be a pain in our large production server farm so I'd like to avoid that). After that, I took into account that our development server, by design, only serves up HTTPS, while I'd been testing in HTTP on my local box. When I enabled HTTPS on my local box, the rewrite rule didn't work with an HTTPS URL but worked fine with an HTTP URL pointing to the same resource.
All the URL Rewrite documentation I've looked at makes reference to HTTP, and there are no references to HTTPS. What am I doing wrong here?
For the record - my local box is running Windows 10, and has IIS version 10. The dev server is running Server 2012, and has IIS version 7.5.
I'm struggling with IIS' URL Rewrite and ARR Modules.
Basically, here's the current state of affairs:
I have a main webserver, awnsering all of my requests. Let's name this MAINWEBSERVER.
I have a secondary server with a specific application that's working as intended if you access it internally but needs to be exposed to the outside via domain to work as a webservice. Let's name this server APPSERVER.
I wish to receive my requests on MAINWEBSERVER and rewrite the URL if it matches my wildcard.
In this case, my Wildcard is https://example.com/MYAPPLICATION* .
And my desired redirect is https://APPSERVER/MYAPPLICATION/WhateverIsLeftInTheUrl .
So here's my rule sitting on my MAINWEBSERVER:
<rewrite>
<rules>
<rule name="Rewrite to Application" patternSyntax="Wildcard" stopProcessing="true">
<match url="https://example.com/MYAPPLICATION*" />
<action type="Rewrite" url="https://APPSERVER/MYAPPLICATION{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
NOTE: I need the URL rewritten for certificate SAN purposes (it won't validate APPSERVER/MYAPPLICATION, so I want to use a mask that is validated by my certificate, such as https://example.com/MYAPPLICATION).
The steps I took were:
Installing ARR (activating proxy settings);
Installing URL ReWrite Module;
Configuring wildcard rule for https://example.com/MYAPPLICATION;
Configuring rewrite for https://APPSERVER/MYAPPLICATION{R:1} (in case it has querystrings I wish to keep them);
Generated personal certificates to validate HTTPS requests between MAINWEBSERVER and APPSERVER;
Whenever I make my request the rule is ignored (despite the same URL matching the wildcard perfectly) and the default website application awnsers, considering my wildcard a querystring parameter.
I've tried this both at server level and at default website level, even with Reverse Proxy Rules. I also have experimented with Fiddler and Failed Request Tracing but to no effect.
In the FRT all that is displayed is a 302 HTTP CODE and in the end a 200 Status Code when the default website loads.
Note that I believe this was working on a different server before, using this same rule although there was no default website.
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}");
We are replacing an existing Apache hosted web site with an ASPX IIS 7.5 hosted web site.
At present, Google displays several sub page results (relative to the main site) where the sub page (Apache) link looks something like this...
http://mysite.co.uk/mypage.html;jsessionid=D4F2C4D93229A451BCA886061501C777
I want this link to be (301) redirected by IIS to something like this...
http://mysite.co.uk/anotherpage.aspx
I can create an 301 HTTP redirect in IIS to redirect "mypage.html" to "anotherpage.aspx" but that doesn't work when the incoming request for "mypage.html" also includes the ";jsession=...".
I've looked at redirect wildcards but I can't seem to get the right result.
Any advice would be much appreciated!
I solved this problem with IIS URL Rewrite. The following sample rule would solve the problem I described above...
<rewrite>
<rules>
<rule name="mypage">
<match url="^mypage.html" />
<action type="Rewrite" url="anotherpage.aspx" appendQueryString="false" />
</rule>
</rules>
</rewrite>