Different behaviors in render without www in url - asp.net

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...

Related

urlrewritingnet - rewrite URL with subdomain

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.

URL Rewrite error with Web Applications

I am running an ASP.NET 4.0 website using IIS7 on Windows Server 2008 R2.
The site has a number of Web Applications under the main domain (~/site1, ~/site2, ~/site3, etc...). Each Web Application is an instance of the same website source folder (D:\Websites\MySite), so you can access the same website at any of the following URLs:
www.mydomain.com
www.mydomain.com/site1
www.mydomain.com/site2
www.mydomain.com/site3
The same website is returned each time, but with slightly different content depending on which specific URL is called.
Everything has been working fine for months until I was asked to add some SEO optimizations using URL Rewrite. Every URL Rewrite rule I add produces the following error:
HTTP Error 500.52 - URL Rewrite Module Error. The page cannot be displayed because an internal server error has occurred.
Config Error: Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'AddTrailingSlashRule1'
I have read elswhere that surrounding the <system.webServer> configSection in the web.config file with:
<location path="." inheritInChildApplications="false">
will fix this problem.
However, while it stops the error message from appearing, it also stops the URL Rewrite rules from working in any of the Web Applications (~/site1, ~/site2, ~/site3).
How can I get the URL Rewrite module to work with Web Applications?
Thanks for any help you can offer.
Add a clear to prevent the duplicate errors on subsites.
<rules>
<clear />
<rule name="Redirect rule for /maps">
....
</rule>
</rules>

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.

ASP.net simple rewrite rule

I'm trying to rewrite non www to www domains.
I've tried the rule:
<rewrite url="http://domain\.com(.+)" to="http://www.domain.com$1" />
But to no avail. It just continues to allow access to htttp://domain.com
Most likely you are refering to this one ("Intelligencia URL Rewriter").
As described in their documentation, you have to add the configuration section handler as well as other configuration settings to your web.config file before you can start adding rewrite/redirect rules.
Update
Just saw you modified your question, so probably you managed to find the configuration issue.
For your domain issue, I handled something similar in one of my projects like this:
<!-- Ensure that all are on the same top domain and sub domain. -->
<unless header="HTTP_HOST" match="www.zeta-producer.com">
<redirect
url="^(.*)$"
to="http://www.zeta-producer.com$1"
processing="stop" />
</unless>

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