• 0

301 Redirect Question


Question

Hi everyone.

 

I am trying to do a 301 Redirect and each time I attempt to do so I somehow mess it up and make the site unavailable...

 

So, I wanted to ask on here what I'm doing wrong and how I can do this.  I have a web.config in my site directory and everything else seems to work (I have it redirecting to an error page if the page isn't found, etc.).

 

But the 301 I've had a lot of issue with.

 

Here is my web.config:

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
            <rule name="www redirect" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
</rule>
<rule name="www redirect https" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^[^\.]+\.[^\.]+$" />
        <add input="{HTTPS}" pattern="on" />
    </conditions>
    <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
</rule>
        <defaultDocument enabled="true">
            <files>
                <clear />
                <add value="index.aspx" />
                <add value="index.asp" />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="home.aspx" />
                <add value="home.asp" />
                <add value="home.htm" />
                <add value="home.html" />
                <add value="default.aspx" />
                <add value="default.asp" />
                <add value="default.htm" />
                <add value="default.html" />
            </files>
        </defaultDocument>
        <httpErrors errorMode="Custom">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/moved.html" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

 

So, what do I put where?  lol  I REALLY appreciate the help.

-Matt-

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Why not use .htacces?

It's a Windows Hosting, so my understanding was that I had to use a web.config file...

 

Sorry, I should have mentioned that.

Link to comment
Share on other sites

  • 0
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/moved.html" responseMode="ExecuteURL" />
            <remove statusCode="301" subStatusCode="-1" />
            <error statusCode="301" prefixLanguageFilePath="" path="/moved.html" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
</configuration>

Above code at the end will do I think, never really used windows servers that much but it looks like the most obvious :P 

Link to comment
Share on other sites

  • 0

Thanks, let me try that and I will post back.  I really appreciate the help.  Every time I try to do this I inadvertently take the whole website down...  :|

Link to comment
Share on other sites

  • 0

Alright, I tried that, and it didn't seem to work.  I have searched online a ton but have not been able to find a solution that worked either...

 

I tried reworking the suggestion like so: 

 

            <remove statusCode="301" subStatusCode="-1" />
            <error statusCode="301" prefixLanguageFilePath="mysite.com" path="www.mysite.com" responseMode="ExecuteURL" />
 
But that didn't work either...
 
Does anyone have any ideas?  I really don't know what I'm doing wrong here...
 
Thanks Again for the help.
Link to comment
Share on other sites

This topic is now closed to further replies.