Canonical name redirects in Godaddy?

2019-08-12 23:31发布

问题:

I have a website "mywebsite.com" and I would like to do a 301 redirect of "http://mywebsite.com" to "http://www.mywebsite.com" (for the usual SEO purposes).

I am running IIS7, however there is an ISA server firewall in front of the site, which seems (as per this article, though his solution did not work for me -- http://mrvirtual.de/2009/07/04/url-rewrite-through-isa-server-ends-in-a-loop/) to be causing the rewrite rule to go into an infinite redirect loop.

DNS is being managed by Godaddy (TotalDNS). Is there a way to configure DNS, or domain forwarding, so that I can accomplish the redirect prior to reaching the ISA firewall / IIS? This seems easier (if possible), than trying to track down and fix the ISA, IIS problem (though if someone has a solution for that, I'll take it).

回答1:

First result for "IIS redirect to www":

http://www.xoc.net/works/tips/domain.asp



回答2:

If you are using IIS7 and you're using .Net 3.5 (at a minimum) the quickest way IMHO is to just quickly add this to your web.config file.

<system.webServer>
<rewrite>
<rules>
    <rule name="CanonicalHostNameRule1">
        <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
        </conditions>
        <action type="Redirect" url="http://www.example.com/{R:1}" />
    </rule>
</rules>

Note: in this example its from a non www url to a www url

Hope this helps buddy.



回答3:

I retract my statement that the article above did not solve the problem. I just didn't try enough variations. In the ISA server policies, "To" tab, "This rule applies to this published website" textbox, I changed the field from www.mywebsite.com -- which is how it is listed in IIS) to just be MyWebsite... it appears that I could make this any text string, as long as it is not the name of the actual site as used in the redirect (both mysite.com & www.mysite.com caused the infinite loop). Changed it as described above and problem solved. Thanks for the nudge mcandre. – Gene 0 secs ago



回答4:

If you are developing on ASP NET, then there is a simple fix that you can apply by using the application_beginrequest event of the global asax

Here is a detailed explanation http://www.xaviermorera.com/2010/01/fix-canonical-redirect-issue-on-asp-net-in-a-shared-host-rackspacecloud/



回答5:

Why do try complex things? Just try the below code with the filename .htacces and upload in the root folder of your website host server (public_html).

RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^/?$ "http://example.com/" [R=301,L]