Windows – How to 301 redirect a single file or directory on a GoDaddy shared Windows hosting plan

301-redirectgodaddyredirectwindows

I've seen a few posts about redirecting domains on GoDaddy, but nothing about single files.

In my case I am using a Windows shared host, so I can't use any IIS management tools. What I'm hoping is that I can do something equivalent to Apache's .htaccess file to configure redirects for single files.

Alternatively, is there an HTML document I can return that performs the same function as an HTTP 301 redirect?

I should point out that I am using plain HTML served from the disk, so I cannot return a custom HTTP response code as I might be able to with say PHP, ASP.NET, ASP, etc.

GoDaddy's documentation does not cover this situation.


EDIT

So user78940's answer shows a viable technique (GoDaddy support <rewrite> in Web.config), however despite reading a few different tutorials on this config element I'm still having trouble getting it to work.

Firstly, I'm using virtual hosting which means I have this physical folder structure:

root                      < -- used for primarysite.com
    - drewnoakes.com      < -- nested virtual hosting
    - someothersite.com   < -- nested virtual hosting

There are three websites here. The root is for primarysite.com, the subdirs are for the correspondingly named sites. This is just how you have to do it with GoDaddy unfortunately. You always have one primary then nest sites there.

Unfortunately the GoDaddy setup gives a redirect if you don't put a trailing slash on a URL (to access the default document of that folder) which means:

http://drewnoakes.com/code/exif (no trailing slash)

…gets redirected to…

http://drewnoakes.com/drewnoakes.com/code/exif/ (with trailing slash)

This means that Google has both URLs in its index. I want to tidy this situation up, making the former redirect properly and the latter redirect to the canonical form so that I don't suffer page-rank dilution and my URLs are less embarrassing easier to remember.

I tried this config, but it ended up with an infinite 301-redirect loop:

<rewrite>
  <rewriteMaps>
    <rewriteMap name="StaticRedirects">
      <add key="/drewnoakes.com/code/exif/" value="/code/exif/" />
    </rewriteMap>
  </rewriteMaps>
  <rules>
    <rule name="RedirectRule" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

So, how can I configure IIS wildcard redirects for this scenario using the <rewrite> configuration element?

Best Answer

The <meta HTTP-EQUIV="REFRESH"....> method will return a 200 response (not a true redirect response like 301/302/etc.).

Afaik Go Daddy has no feature in their control panel for redirecting only certain files on shared Windows accounts.

On a shared Windows plan you may be able to use IIS 7 URL rewriting via a web.config file put in the root of your website directory. You would have to confirm that your particular hosting account is on a IIS 7+ server. If so, add the following web.config file to perform a simple redirect:

    <?xml version="1.0"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rewriteMaps>
                <rewriteMap name="StaticRedirects">
                    <add key="/somedir/old-page.html" value="/otherdir/new-page.html" />
                </rewriteMap>
            </rewriteMaps>
            <rules>
                <rule name="RedirectRule" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Redirect" url="http://www.somedomain.com{C:1}" appendQueryString="False" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

For more details you can see the "Using rewrite maps for redirection" section here: http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/

Related Topic