301 Redirect with ColdFusion dynamic url - 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!

Related

URL Rewrite match question mark

I am trying to match a ? in my url rewrite section in my web config, I am using IIS Express so I can not add the rule via IIS manager.
<rules>
<rule name="LocationDetail" stopProcessing="true">
<match url="^location-detail\?province=([A-Za-z]{2})$" />
<action type="Redirect" url="LocationDetail"/>
</rule>
</rules>
As you can see I am already escaping the ?. Is there something I am missing?
I also modify the url so that the the question mark is not needed to see if the question mark is the reason it was not matching.
<rules>
<rule name="LocationDetail" stopProcessing="true">
<match url="^location-detailprovince=([A-Za-z]{2})$" />
<action type="Redirect" url="LocationDetail"/>
</rule>
</rules>
It was. Once the question mark was removed it matched correctly and I was redirected correctly.

Replace %5E in URL using IIS Rewrite

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>

IIS URL Rewrite is not working when redirecting to another server

I need to redirect links to a different server using URL rewrite in IIS. These are SRSS report links. I have tried so many different configurations i have given up.
Old Link:
http://OldServer/ReportServer/Pages/ReportViewer.aspx?(reportnamehere - need to copy this part across to new link)
http://NewServer/ReportServer/Pages/ReportViewer.aspx?reportnamehere
Any ideas how this can be achieved?
This is a very simple rule requirement. Something like this will work. Basically just redirects to a new server appending the entire URL
<rule name="Redirect to newServer" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="http://NewServer/{R:1}" redirectType="Temporary" />
</rule>

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>

IIS 7.5 URL Rewrite - Redirect from http to https for account controller but from https to http for everything else

I've found bits and pieces of what I need to make this work, but haven't been able to bring everything together into a workable solution.
I am working on an intranet site, and want to secure *just the logon and logoff actions on my account controller with https. I have the certificate installed correctly, and can successfully redirect traffic to these controller actions to https using a UrlRewrite rule:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="^account/logon$|^account/logoff$" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
Now, however, I also want to redirect *all of the rest of my site's requests (other than traffic to the two actions) back to http. I'm not interested in debating the merits of this approach, as I have what I consider valid reasons for wanting to redirect back out of https to http.
I've tried writing some code in the Actions to achieve this, but am having major issues with this. I don't know if it is because I'm working with two load-balanced servers or what, but anything I try just gives me a "too many redirects" error message.
So, two questions:
Is it better to use a UrlRewrite rule to redirect out of https or a controller actions?
Does anyone have a working code example or something that can at least get me started down the right path?
Any help is much appreciated!
Better late than never. This might help you or someone else.
<rule name="Redirect to HTTP">
<match url="secureDir/(.*)" negate="true" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="secureDir/(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
First, you will have a bit of a challenge here insofar as non-page resources -- how are you referencing images and stylesheets?
As for the question at hand, I think you want to force this upstream of the web servers, such as on the load balancer. I would also backstop the account controller by adding a RequireHttps attribute.
Finally, remember that even if the login process is secured, if that cookie is not transmitted over HTTPS you can easily end up with a firesheep like scenario.
I have some code here which lets you control this with attributes.
MVC already has a [RequireHttps] attribute which you would apply to your logon/logoff pages. My code extends this approach and gives you an additional [ExitHttpsIfNotRequired] attribute. With this attribute applied to your base controller, when you try to access any action with HTTPS that doesn't have [RequireHttps], it will redirect you to HTTP.

Resources