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

5,590

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/

Share:
5,590

Related videos on Youtube

Drew Noakes
Author by

Drew Noakes

Updated on September 18, 2022

Comments

  • Drew Noakes
    Drew Noakes almost 2 years

    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?

  • Drew Noakes
    Drew Noakes about 13 years
    Is that really equivalent to a HTTP 301 response though? Will Google and other search engines update their references to the page?
  • Drew Noakes
    Drew Noakes about 13 years
    This looks quite promising indeed! I'll give it a shot and get back. Thank you.
  • Drew Noakes
    Drew Noakes about 13 years
    So I had a chance to test this out and it looks promising. For simple redirects (ie. fixed URLs) I found the httpRedirect element simpler (see the answer I posted [here(serverfault.com/questions/262575/…) but this looks good for wildcard matching. I am still a bit stumped (getting redirect loops) so have updated my question. Would you mind taking another look? Thanks again.
  • iainlbc
    iainlbc about 13 years
    @Drew I think google/yahoo treat it as a 301 if you do a no-delay "0" refresh. Still looking for a source
  • iainlbc
    iainlbc about 13 years
    Hmm. not really clear. Google seems to officially recommend a 301 over a meta refresh. google.com/support/webmasters/bin/answer.py?answer=79812 Most posts/forums on the topic are very dated (2007/08). Cheers
  • Drew Noakes
    Drew Noakes about 13 years
    Not to mention that a meta-refresh causes quite a bit of flicker in the browser compared to a 301. Even if a meta updates a search engine's index, but it won't patch people who've hard coded the old URL elsewhere on the web. Those who follow such links will see this flicker.