Replace %5E in URL using IIS Rewrite - ios

I have the following problem:
I send a request via HttpResponse.Redirect method to a web application:
http(s)://localhost/application?arg1=abc^def
This works pretty fine on IE/Edge/Chrome/Firefox. But on Safari I get the problem that the request is sent as following encoded string:
http(s)://localhost/application.aspx?arg1=abc%5Edef
The application does not like/accept that and I am not able to perform changes on the application.
Is it possible to rewrite the URL on the webserver where the application is hosted by IIS Rewrite module somehow?
I tried already to create a rule with following regex pattern:
^application?(.\*)%5E(.\*)
and the following action:
Rewrite URL:
application.aspx?{R:1}%5E{R:2}
...but this does not seem to work (although the regex pattern has passed the "Test Pattern" test)
Many thanks in advance!

This is because there is a problem with your rewrite rules. The following configuration will rewrite http://localhost/application.aspx?arg1=abc%5Edef to http://localhost/application?arg1=abc^def:
<rewrite>
<rules>
<rule name="TEST" stopProcessing="true">
<match url="(application.aspx)" />
<action type="Rewrite" url="http://localhost/application?{C:1}^{C:3}" appendQueryString="false" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)(%5E)(.*)" />
</conditions>
</rule>
</rules>
</rewrite>

Related

301 Redirect with ColdFusion dynamic url

Long time listeners, first time callers.
We are trying to accept old inbound links, that are currently bouncing.
The old urls contain: /County_Detail.cfm/CountyID:XXX   (XXX = UniqueID)
We want the old links to redirect to /Counties/County_Detail.cfm?CountyID=XXX
We're using CF10 and IIS 8.5
We simply want to replace the delimiters / and :
We've tried a number of settings, with the following as the latest: 
<rewrite>
<rules>
<rule name="Rewrite Counties" stopProcessing="true">
<match url="^County_Detail.cfm([a-zA-Z0-9-+]+)CountyID([a-zA-Z0-9-+]+)" />
<action type="Redirect" url="County_Detail.cfm{R:1}CountyID{R:2}" />
</rule>
</rules>
</rewrite>
Would someone kindly point out the error of our ways.
Thank you, so much!

IIS URL Rewrite multiple parameters

I am really confused about the URL rewrite interface. I dont understand what i need to do.
I have an url as:
www.example.com/diretory/subdirectory/index.html?param1=1&param2=2&param3=2&param4=7
I want to hide this url in a <a>-href tag, which displays "Example Tag".
When the url is requested it should rewrite it to
www.example.com/program/location/year/vacancie
I allready tried this:
<system.webServer>
<rewrite>
<rules>
<rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="\?([^/]+)&([^/]+)&([^/]+)&([^/]+)" />
<action type="Rewrite" url="www.example.com/program/location/year/vacancie" logRewrittenUrl="true" />
<conditions>
</conditions>
</rule>
</rules>
</rewrite>
</system.webServer>
In the URL Rewrite Interface the Test Pattern said it is working and gets:
?param1=1&param2=2&param3=2&param4=7
param1=1
param2=2
param3=2
param4=7
I checked the log url rewrite as well, but in my logs it is not shown.
2017-03-20 16:29:24 192.168.253.146 GET /diretory/subdirectory/index.html param1=1&param2=2&param3=2&param4=7 88 - 192.168.253.146 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 304 0 0 4
ps: the urls are not working and only for illustrative purpose.
The match URL only matches the URL and does not take the querystring into account. You will need to add a condition for this. Also do you want to rewrite this (so the server internally executes the new URL) or redirect (so the server will request the browser to go to the new URL and URL changes in address bar). In case you want to rewrite you should not add the domain again, in case you want to redirect add http:// as well. Assuming a rewrite is what you want use below rule:
<rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="/program/location/year/vacancie" logRewrittenUrl="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="([^/]+)&([^/]+)&([^/]+)&([^/]+)" />
</conditions>
</rule>

HTTP Error 404.4 - Not Found - URL Rewrite - IIS Express

I am building an application using ASP.NET MVC + AngularJS. Now to make API calls through AngularJS, I am using URL rewrite because APIs are hosted on different servers.
but it gives me 404.4 error. I checked the trace for the request and patterns are matching fine. It is trying rewrite to the server url, but then it gives 404.4 error.
I have also added in my web.config. My rewrite rule is as follows:
<rewrite>
<allowedServerVariables>
<add name="HTTP_Authorization"/>
</allowedServerVariables>
<rules>
<rule name="Api Call" stopProcessing="true">
<match url="quote/(.*)" />
<action type="Rewrite" url="http://<server>/pc/service/edge/quote/{R:1}" appendQueryString="false" />
<serverVariables>
<set name="HTTP_Authorization" value="Basic <key>" />
</serverVariables>
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="quote/(.*)" />
</conditions>
</rule>
</rules>
</rewrite>
What am I doing wrong?
Please help. Thank you in advance.
You need to install IIS Application Request Routing: Visit https://www.iis.net/downloads/microsoft/application-request-routing
Check the “Enable proxy” checkbox located in Application Request Routing feature view is IIS Manager

IIS URL Rewrite not working with query string

I thought this was pretty straightforward, but it refuses to work. The old URL is
http://www.site.com/?q=node/17
It needs to redirect to http://www.site.com. I don't need to worry about wildcards, this is the only query string parameter I need to worry about. The rule I wrote looks like
<rule name="Node17" patternSyntax="ExactMatch" stopProcessing="true">
<match url="http://www.site.com/?q=node/17" />
<action type="Redirect" url="http://www.site.com" appendQueryString="False" />
</rule>
I can test the pattern inside of IIS and it matches, but when I hit the URL in a browser it doesn't redirect. Any thoughts?
As described in Microsoft's documentation:
It is important to understand how certain parts of the URL string can
be accessed from a rewrite rule.
For an HTTP URL in this form:
http(s)://{host}:{port}/{path}?{querystring}
The {path} is matched against the pattern of the rule. The
{querystring} is available in the server variable called QUERY_STRING
and can be accessed by using a condition within a rule.
Rule conditions allow defining additional logic for rule evaluation...
Rule conditions are evaluated after the rule pattern match is successful.
In the URL you wanted to rewrite as a redirect, your {host} = "www.site.com", {path} = "" and {querystring} = "q=node/17". So the {path} part in the URL you wanted to redirect is actually empty, and the rule you used in your question was matched against it and did not match.
Your solution is indeed valid, so I'll quote it here:
<rule name="Node17" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="q=node/17" />
</conditions>
<action type="Redirect" url="http://www.example.com" appendQueryString="False" />
</rule>
Of course I figured it out soon after I posted. This does it, not really sure why the exactmatch wasn't working though.
<rule name="Node17" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="q=node/17" />
</conditions>
<action type="Redirect" url="http://www.site.com" appendQueryString="False" />
</rule>

Redirect to non-www-url domain with MVC4 / IIS7.5

First of all, I just spent a few hours on Stackoverflow reading similar questions but no answer seems to work for me.
I have an MVC4 application which has an SEO issue : the non-www is not redirected to www. I have installed the Rewrite module on the server (IIS7.5) and on my local environment (VS2010).
I tried many ways but none seems to work...
Ideally, I would prefer to have the rewrite rule in my MVC4 solution and avoid doing server side configuration as it is more convenient when deploying to new servers.
I tried to put the following code block in my web.config :
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<!-- code added for SEO non-www to www redirect -->
<rewrite>
<rules>
<rule name="Remove WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<!-- SEO code -->
</system.webServer>
I then published the solution (with the right domain name) but nothing changes. When trying to access http://domain.com, I just get a 404 not found error.
I tried several code block for this part but it just never work. I also tried to configure this on the server, which didn't work as well. The best solution would be to have this rewrite in my web.config so the rules are applied whenever I publish to a new web server.
Does anyone sees something wrong with this ? My web.config is in my MVC4 application and published via the Publish menu we get when right-clicking the solution in VS2010.
Thank you very much in advance for your replies.
I also tried this block for the rule but it doesn't change anything..
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" redirectType="Permanent" />
</rule>

Resources