Coldfusion to .NET pages .cfm to .aspx in Web.Config - asp.net

Creating redirects for Coldfusion pages to .Net pages through web.config. Looking for guidance on handling .cfm request and converting them to .aspx on a windows server with IIS 7.5. Ideally 301 redirects for SEO purposes.
Anyone know an efficient way to handle .cfm request and convert them to .aspx through web.config?

I work with Coldfusion 9.x.x on IIS 7.5 and 8 and here is what we do.
Say you have a link that appears like this:
http://example.com/index.cfm?articleid=12&displayText=title-of-the-article
You'll need this basic structure added to your web.config file:
<rewrite>
<rules>
<rule name="Article Stripper" stopProcessing="true">
<match url="^([\w-_+]+)/([\w-_+]+)" ignoreCase="false" />
<action type="Rewrite" url="/index.cfm?articleid={R:1}&displayText={R:2}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
To produce something like this:
http://example.com/12/title-of-the-article

You can do using Application_BeginRequest() event in Global.asax.
Please check out following link for further details on it.
Asp.net processing of .CFM files or Redirects from .cfm to .aspx page

Related

Using IIS rewrite rules to rewrite from main website to sub application

We have an ASP.NET Web API application (.NET 4.*) which is hosted as a website in IIS. The ASP.NET application contains server-side rendered pages, but also a REST API which is available at /api/v1.
A new API is in development, which is using ASP.NET Core (.NET 7) and will be hosted as an IIS application (believe me, we cannot get around that for now) under the main website (which contains the ASP.NET Web API application).
The new API should also be available on /api, but since this is an application under the main website, if we would use /api for the new application, the REST API of the main website would not receive requests anymore. Hosting it under /api/v2 is not possible as IIS applications cannot contain a / in the alias (and we also do not prefer a version in the path anymore).
Instead, we would like to create the application using another name, /foo for example, and use rewrite rules in the web.config to rewrite from the main website to the new application, eg.:
<system.webServer>
<rewrite>
<rules>
<rule name="Foo">
<match url="^api\/((?!v1).*)$" />
<action type="Rewrite" url="foo/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
But this doesn't seem to work. It looks like the request is rewritten, but still handled by the main website, not by the sub application. Is it not possible to rewrite (not redirect!) a request from a website to a sub application within that website? If not, any other suggestions to host both applications on the same starting path (it should remain two separate applications)? At the moment, there is no possibility for a reverse proxy which could solve this issue.
If you want to access requests starting with /api by typing /foo in the browser address bar, you can try the following rule:
<system.webServer>
<rewrite>
<rules>
<rule name="Foo">
<match url="foo(.*)" />
<action type="Rewrite" url="api{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>

Single WebApplication with multiple domain names

For example, I have a Web Application www.mywebsite.com based on classic ASP.NET and IIS 7.5. Now I registered another domain name www.mywebsite.cc. In my Web Application I want to create subfolder /cc and somehow transparently rewrite all requests from www.mywebsite.cc/something to www.mywebsite.com/cc/something. Why I need this? I want both websites to share same static variables, cache, database connections etc. Please point me what technology I must dig in order to implement what I need.
There are a couple of ways to do this, you might try URL rewriting. Your code might look something like this, but you'll need to adjust the line following string: "^something/?$|^something/(.*)$" to contain the proper match code. This should get you started and hopefully someone else will be able to comment on the proper match code.
<rewrite>
<rules>
<remove name="RedirectToUtility"/>
<rule name="RedirectToUtility" stopProcessing="true">
<match url="^something/?$|^something/(.*)$"/>
<conditions/>
<serverVariables/>
<action type="Redirect" url="http://www.mywebsite.com/cc/something/{R:1}"/>
</rule>
</rules>
</rewrite>
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

app_offline.htm not working for rewritten URLs

I have a Rewrite rule for a specific page, to make it more SEO friendly.
<rewrite>
<rules>
<rule name="Friendly Threads">
<match url="Topic/([^/]*)/([^/]*)/[^[#\?]*\??(.*)" />
<action type="Rewrite" url="thread_messages.asp?ThreadID={R:1}&PageNumber={R:2}&{R:3}" />
</rule>
</rules>
</rewrite>
But whenever I drop an app_offline.htm file in the root, the site will go to the app_offline.htm page for all URLs except for those matching the above match.
Is this expected, or have I possibly got something misconfigured somewhere?
If it makes any difference, this is a classic ASP site running under IIS 8 (Windows 2012).
(And yes, I know this is like putting a 90 year old behind the wheel of a Lamborghini.)
As far as I know app_offline.htm only works for ASP.NET. As the rewrite result is classic ASP, the page is handled by another IIS module, so it won't care about app_offline.htm existence.
In another saying, you have done nothing wrong, but classic ASP does not support app_offline.htm.

hiding the path of a file on web server

I have a webpage that host documents on iis. When linking to those files for examples say I go to
www.webpage.com/Documents/testdocuments/innerfolder/1.pdf
I get the file back and have the complete url in the address bar. Is there a way to be able to browser to
www.webpage.com/Documents/testdocuments/innerfolder/1.pdf
, and get for example
www.webpage.com/Webdocs/1.pdf
as the url in the browser. My theory was make
www.webpage.com/Documents
a virtual directory, but I am not sure if I would still be able to access my files as
www.webpage.com/Documents/testdocuments/innerfolder/1.pdf
or if I would have to use for example
www.webpage.com/Webdocs/testdocuments/innerfolder/1.pdf
which defeats the purpose really. My ultimate goal is for the physical path of the file to not be visible to the user.
Any ideas would be greatly appreciated.
Thanks,
Since you are looking only to map one path to another you should use IIS url rewriting.
<rewrite>
<rules>
<rule name="Map Docs" stopProcessing="true">
<match url="^Webdocs/([_0-9a-z-]+)" />
<action type="Rewrite" url="Documents/testdocuments/innerfolder/{R:1}" />
</rule>
</rules>
</rewrite>
The other alternative is asp.net url routing. But it would be an overkill for what you need.

Multiple Country/Language Sites Under Single Web Application - TLD Routing Rewrites

I want to host multiple Top Level Domains (TLDs) off of the same web application.
Scenario: www.mywebsite.com has language sub-folders of /en-us/, /en-gb/, /fr-ca/, /ja/, etc...
So www.mywebsite.com/en-gb/ would be the UK version of the site.
UK users should go to www.mywebsite.co.uk but be routed to www.mywebsite.com/en-gb/
In IIS, I've set the bindings for this web application to handle both www.mywebsite.com and www.mywebsite.co.uk domains.
The URL Rewrite 2.0 module is added to IIS and includes this rule:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mywebsite\.co\.uk$" />
</conditions>
<action type="Rewrite" url="http://www.mywebsite.com/en-gb/{R:1}" />
</rule>
</rules>
</rewrite>
Users who go to www.mywebsite.co.uk have the URL rewritten to www.mywebsite.com/en-gb/, however, I want the URL to remain www.mywebsite.co.uk for them, and in fact, I would want the www.mywebsite.com/en-gb/ to be rewritten to www.mywebsite.co.uk for consistency.
I'm still not even quite sure what the proper terminology is for what I want to do. So far I've run across 'multi-tenancy', 'application request routing', 'URL routing', 'URL rewriting', and a few others.
Here are a few resources I've been reading to try and figure out how best to handle this. Am I on the right track? I haven't found a good example that demonstrates doing this with TLD's.
Scott Forsyth - Multiple Domains Under One Site
Scott Guthrie - URL Routing With ASP.NET 4 Webforms
Stackoverflow - MVC Routes Based On A SubDomain

Resources