urlrewritingnet - rewrite URL with subdomain - asp.net

I have umbraco website setting on an IIS 7 server: WWW.SITE.COM
I would like rewrite the URL WWW.SITE.COM/SIGUNP to WWW.SIGNUP.SITE.COM
is it possible by using urlrewritingnet or should I configure this by using DNS Host?

I would use HTTP Redirect in IIS to achieve this. I'd recommend using permanent (301) as response status, this will also force most search robots to update their indexes.
Add everything inside the configuration elements to your web.config file
<?xml version="1.0"?>
<configuration>
<location path="signup">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.signup.site.com" exactDestination="false" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
exactDestination="false" will turn http://www.site.com/signup/anything/example.html into http://www.signup.site.com/anything/example.html
exactDestination="true" will turn http://www.site.com/signup/anything/example.html into http://www.signup.site.com/

There are several approaches to doing this and Eric's approach is a perfectly valid one. You can also use UrlRewriting.Net as you suggest but I think Eric has suggested the baked in <httpRedirect /> approach as it can be configured in the web.config and therefore also in IIS7 manually.
The disadvantages to this approach however are that:
It needs a developer to update the web.config; or
Someone with access to IIS to change the configuration
It requires an application restart to pick up the redirect rules
There are two other approaches you should consider:
A HttpModule that uses a CSV file containing a cached list of 'from' and 'to' URLs;
A Umbraco-managed doc type that can handle specific path redirects.
The HttpModule approach obviously requires a little coding but is very rewarding. Your SEO team/client can provide a list of URLs that need redirecting and your HttpModule can cache the list (using the file as a dependency) and perform the redirects based upon matched URLs. Any update to the file simply clears the cache automatically.
For basic redirects, I like the approach of having a "Redirect" doc type in Umbraco. This doc type will have two fields, a "redirect type" field (301/302) and a "redirect to" field. In the template for this doc type you will need a little cpde that performs a redirect to the "redirect to" node. Any hits on a page created using this doc type will automatically redirect to the target page. You can also use this doc type in conjunction with "umbracoUrlAlias" field. You can add multiple paths to this field separated by a comma (see this article for an explaination). This way you can catch multiple simliar paths and redirect to a single path.
The advantage of this approach is that it is manageable in the CMS, but the disadvantage is that the redirects are not managed centrally like a CSV file, so you need to be careful in how it is implemented.

Related

How do I bypass Accept header validation in IIS?

I have a Nancy website hosted on ASP.Net with a number of custom routes. These routes include mappings which look like file paths (e.g. /path/to/xml_file.xml), but that resolve to HTML files which should display in the browser. For most files, this works correctly. However, with XML files (and possibly other mime types), I am getting a 406.0 HTTP error from IIS 8 Express explicitly stating that
HTTP Error 406.0 - Not Acceptable
The resource cannot be displayed because the file extension is not being accepted by your browser.
The request was rejected because it contained an Accept header for a MIME type that is not supported for the requested file extension.
Verify the MIME settings for the file extension that was requested to make sure this MIME type is acceptable.
Is there any web.config setting or other technique for bypassing this validation so that I don't get this error without having to rewrite the path logic? My Google searching is failing me. For example, I have found this IIS forum post linked from the SO Answer which talks about
map all reqests to ASP.NET and use the ASP.NET's StaticFileHandler to serve them
However, the post does not explain how to do this; nor does it seem applicable.
Edit: (Added error page image above)
As another tidbit, the Nancy route returns an explicit view of the form
return View["view_name", myModel];
And therefore, should bypass content negotiation.
While not a fix or answer per se, my current work around (for anyone who might be interested) is to tweak the routes to use a trailing slash. As an example:
"/path/to/xml_file.xml" // Still returns a 406.0 error
"/path/to/xml_file.xml/" // Works properly (notice the trailing slash)
Here's a link to the Rackspace knowledge center that shows how to change the MIME mapping for static content in the web.config file.
https://www.iis.net/configreference/system.webserver/staticcontent/mimemap
There's also this one from MS that's more in-depth.
https://www.iis.net/configreference/system.webserver/staticcontent/mimemap
They both feature this stanza from the web.config file.
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".extension" />
<mimeMap fileExtension=".extension" mimeType="application/example" />
</staticContent>
</system.webServer>
</configuration>
If that's how to actually fix the 406.0 problem...

Rewrite Maps in IIS Make web.config Too Large

I am migrating a website which is/will be running on IIS and I will be using rewrite maps to 301 redirect old ".asp" URLs to a new style of URL. For many thousands of URLs there is no pattern, so it appears I must rely on rewrite maps.
My problem is that the default web.config size limit is 250kb, and in my environment, I don't have access to change this (as can be done at the registry level - if one had access).
I have looked into moving the rewriteMaps section to an external file, but the external files also have the default size limit of 250kg, so this is also not going to work.
I am looking for some other way to handle this... I am sitting at 242kb currently and have over twice the amount of old to new redirect mapping to add.
Thanks in advance.
As I am in a shared environment, there was no solution other than to move it to a single external config file, which was again, limited to 250KB.
So here is what I did:
I filled up the map to capicity with the highest-trafficked redirects and of course any groups of urls that could be redirected using a pattern (so they would be fastest).
For the 100k remaining long-tail of the redirects, I put them into a REDIRECTS table in the db... SO, after the request passes all of the rewrite rules in the file (and of course, doesn't hit any), it defaults the request to a certain script. One of the first things the script does is check the REDIRECTS table, and if an entry exists, I do a redirect in the code... it's slower, but most of the stuff in the table is long tail, and as I said, the most visited redirects are still in the file. This has worked well for me so far, and I can add as many redirects as I want... e.g. if a page title/url gets edited, my admin area automatically adds the redirect, etc.
The Nativerd.dll file uses the value of this registry key to determine the maximum allowed size, in KB, of the Web.config files. The Configuration system assumes a default value of 250 KB in Windows Server 2008 and 100 KB in the release version of Windows Vista.
The reason for the 250KB limit is to reduce attacks for uploading a large web.config file. You can change the the limit by altering the upper value in your registry:
HKLM\SOFTWARE\Wow6432Node\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (REG_DWORD)
See: Description of the registry keys that are used by IIS 7.0, IIS 7.5, and IIS 8.0
Another option is to split your web.config files into multiple smaller files.
We were stuck on this for a long while, we ended up writing our own 301 redirector. In sitecore it was in a pipeline patched after ItemResolver which consumes the large file (not included in any Web.configs). We could not use the "registry hack" option as it an Azure Service App and there is no (easy and cheap) access to the registry.
You can split up your configuration into a few different files as Neill said.
You will have a main web.config file in which you’ll reference sub config files by adding a configSource attribute onto the sections you would like to split into other files.
For example, if you’d like to split the section “appsettings” in another file, you would change the appSettings section in your web.config file to :
<appSettings configSource="appsettings.config" />
and in the appsettings.config file, you would add all your appsettings entries like they were in the original web.config file, for example;
<appSettings>
<add key="aspnet:RestrictXmlControls" value="true" />
<add key="FeedCacheTime" value="300" />
<add key="FeedPageUrl" value="/_layouts/15/feed.aspx?" />
<add key="FeedXsl1" value="/Style Library/Xsl Style Sheets/Rss.xsl" />
<add key="aspnet:AllowAnonymousImpersonation" value="true" />
</appSettings>
Obviously with the rewrite maps instead.

Different behaviors in render without www in url

I have an issue on my website.
It seems that a page has different behaviors when the URL contains (or not) the "www".
It looks like it remove all my query strings
http://example.com/test.aspx?name=John
This URL redirect to : http://www.example.com/test.aspx
The project is on ASP.NET 4.0 (Webforms)
Is this in IIS? Do you happen to have the UrlRewriteModule running? Perhaps there are some rewrite rules in your web.config that are performing redirects and dropping the query string. If present, you would see check under the 'system.webServer' tag an entry called 'rewrite' containing your rules:
<system.webServer>
...
<rewrite
<rules>
<!-- make sure there are no undesired rules here doing redirects -->
<rule...

ASP.NET redirect rule for .cfm file

I have a DotNetNuke application where I am migrating all my old web sites all together under portals.
As users are storing old sites URLs into bookmarks, I need to write redirect rules so they can get properly on new page.
Now, at one point I stuck because I am unable to write rule.
My condition is
URL A
http://www.mydomain.com.cn/auto.cfm?myurl=domain/notice_article.cfm
Should redirect to
http://www.mynewdomain.com/home.aspx
I have implemented this using redirectMaps.
e.g.
<rewriteMap name="MyRedirectMap_Entire">
<add key="whttp://www.mydomain.com.cn/auto.cfm?myurl=domain/notice_article.cfm" value="http://www.mynewdomain.com/home.aspx" />
</rewriteMap>
Adding this properly under web.config file, I able to redirect properly.

Extensionless Page Requests

I have a customer of ours that sent out a publication referring to my site but they used the wrong address...they did not provide a page name...it looks like this:
mywebsite.org/Resources/toolkits/bridging
when it should have been
mywebsite.org/Resources/toolkits/bridging/default.aspx
Is there a way to tell ASP.NET to default to this default.aspx when it sees this kind of request or even better, have IIS 7 handle this easily?
This site is live so I would like to avoid having to introduce code if possible.
As per other suggestions, this should be done in the IIS configuration for your website using the IIS Admin tool.
There is however, another alternative - you can add a section in the web.config of your actual ASP.NET application, allowing you to override the IIS configuration right from your application:
<system.webServer>
<defaultDocument>
<files>
<clear />
<!-- Specify each of your files by order of preference here -->
<add value="Default.aspx" />
<add value="Index.aspx" />
<add value="MyOtherPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
The caveat to this though is it may be a little obtuse when the IIS administrator can't figure out why the server configuration isn't working the way he's got it configured. It's not always right to do something just because you can.
Finally, just in case you don't have access to the IIS server or your IIS administrator has reasons for not adding Default.aspx to the default document list in the IIS configuration and for whatever reason, you don't wish to override the IIS configuration in your web.config file, then the quickest and simplest way is to simply create a file called default.asp in that directory containing:
<% Response.Redirect("default.aspx") %>
Default.asp is in the default document list on IIS. The code will automatically redirect the call to the correct page. The downside to this approach though is that there's a performance hit - every time someone calls default.asp - directly or otherwise, the redirect needs to happen which isn't free.
In the Documents tab of the web site properties in IIS you can specify default documents. If you are using .Net2.0 or later on that machine then Default.aspx should already be set....
Default.aspx is not, oddly enough, set as the default document in an IIS installation; In IIS 7, the setting is under "HTTP Features", called "Default Document". Add default.aspx to that list and you should be OK.
If not, you'll need to add a 404 handler that redirects when it sees that URL.

Resources