Sign in to follow this  
Followers 0

301 Redirect Question


6 posts in this topic

Posted

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-

Share this post


Link to post
Share on other sites

Posted

Why not use .htacces?

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

            <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 

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.