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/
Related
I have the following website configuration on IIS 10.
<rewrite>
<rules>
<rule name="Rule1">
<match url=".*" />
<action type="Rewrite" url="https://www.google.com/{R:0}" />
</rule>
</rules>
</rewrite>
I'm trying to rewrite all the requests sent to mydomain.com to google.com (taken as an example)
When running the website, I'm getting the following google error page in the screenshot. Means the rewrite is not behaving properly and doesn't send requests to the domain www.google.com
Can anyone help please ?
Thanks. Regards,
I have .NET MVC application hosted on IIS 10 with the following URL:
https://abc-def-example.com/MyWebsite
I want to use https://abc-def-example.com instead of the above URL.
Note: MyWebsite is name of an application hosted on IIS
How do I achieve this?
Thanks in advance!
You can use the URL Rewrite Rule to rewrite the request on https://abc-def-example.com to https://abc-def-example.com/MyWebsite:
<rewrite>
<rules>
<rule name="Test">
<match url="^(?!MyWebsite)(.*)" />
<action type="Rewrite" url="/MyWebsite/{R:0}" />
</rule>
</rules>
</rewrite>
Apply this rule to https://abc-def-example.com.
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}");
I'm trying to write a rewrite rule in on Windows Server 6.2. Although I used IIS Manager to create the code, it didn't work.
I tried stopProcess true/false, used different regex, restart server several times. Nothing changed. I followed the whole steps on Microsoft's web site on https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="[^\/]+\/\/([^\/]+:?[0-9]?)\/.*" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I want to show only main URL. My domain is http://e-campus.example.com.
For example if someone go to that link: http://e-campus.example.com/Login/Student
Server should rewrite to this:
e-campus.example.com (with hiding http:// but it's not important)
So basically I just want to show main URL. But it keeps showing full path. What am I missing here?
According to your description, I found your regex match the whole url. But the iis url rewrite will not get the whole domain, it will just get the part of the url not the whole url.
For example:
If your url is http://e-campus.example.com/Login/Student., the match url part is
login/Student.
So if you want to rewrithe all the request to e-campus.example.com, you should use below url rewrite rule.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to e-campus" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://e-campus.example.com/" />
</rule>
</rules>
</rewrite>
</system.webServer>
I have two domains: first.com and second.com.
In these domains there are two ASP.NET applications hosted in IIS 7.
Page in application http://first.com.index references a script which source is http://second.com/script.js
Script is doing some ajax POST but browser is blocking is because cross domain restriction.
Is it possible to create rule on IIS so a specific request for http://first.com/script.js
would be passed to http://second.com/script.js (executed there and returned to client) ?
I tried to add rewrite rule in first.com but it does not work:
<system.webServer>
<rewrite>
<rules>
<rule name="test" enabled="true" stopProcessing="false">
<match url=".*/script.js" />
<action type="Rewrite" url="http://second/script.js" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
Action type="Redirect" works but it is not what I am looking for cause it returns 302 response to client. I want pass request directly to second application instead.