301 redirect for an old page in a windows server running IIS 7

Hello There,

I have been getting into SEO a bit and I am also on a windows server opposed to a linux one.  I was quite comfortable in regards to how to do a redirect either for a whole URL or old page in the linux environment but am not so sure about this in the widnows server environment especially one these need to be done on my shared remote hosting provider.

As I was searching the internet I did find a blog in regards to using the web.config file if IIS 7 is the version being served and I will paste some of that blog below as I have further questions first if this makes sense but second how one would tweak this for the scope of a page not just simply a URL redirect so here are the contents below:

---------------------------------------------------------------------------------------------
For this to work, you need to download and enable the URL Rewrite module for IIS 7. Then the following code is used in the ASP.NET web.config file:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"               redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
-------------------------------------------------------------------------------------------
So my question is first of all does this seem right and second if I wanted to redirect an old page like say aboutme.html to a page called default.aspx/aboutme how would I go about doing this using the code snippet above as a point of reference given it is accurate.  Would I simply just add to the path so in the example they gave:

<add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"

would I simply just rewrite this to say domain.com/aboutme.html$"/>...

and the new path to say http://www.domain.com/default.aspx/aboutme(R:0)"...

Would this concept work or would web.config choke because you turned this into a file or page redirection rather than simply a URL redirection.

Thanks for any tips you can give me and by the way if I had multiple pages that needed this redirection what would I do.

would the structure be parsed like the following:

---------------------------------------------------------------------------------------
 <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"               redirectType="Permanent" />
        </rule>
---------------------------------------------------------------------------------------
so that for every page I wished to redirect I would have to copy the tags from <rule>contents</rule> so for example two pages might look as follows:
-----------------------------------------------------------------------------------
 <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com/contactus.html$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/default.aspx/contactus{R:0}"               redirectType="Permanent" />
        </rule>

 <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com/aboutme.html$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/default.aspx/aboutme{R:0}"               redirectType="Permanent" />
        </rule>
----------------------------------------------------------------------------------------------------
Do I have the right concept here?

Thanks,

Bo
cyboramaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Brad HoweConnect With a Mentor DevOps ManagerCommented:
Hi,
There are issue with your rules base, but we can correct those for you today. To start with URL Mod rewrite 2.0, make sure you have the latest version installed.
URL Rewrite Module 2.0 http://www.iis.net/download/URLRewrite
Rules:
First, Redirect domain.com to www.domain.com. Use this as a the rule in your web.config. If you are unsure how this works or what it does, use the IIS Manager URL Rewrite Feature. IIS Manager has a built in GUI for this module.
<rule name="Redirect domain.com to www.domain.com" enabled=true" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping='MatchAny">
                 <add input="{HTTP_HOST}" pattern="^domain.com$" negate="true" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:1}"  />
</rule>
 
Second I'm not understand this url format? aboutme.html to a page called default.aspx/aboutme  
So you want domain.com/aboutme.html to be redirected to domain.com/aboutme/default.aspx?
eg:
<rule name="Redirect aboutme.html to www.domain.com/aboutme/default.aspx" enabled=true" >
          <match url="^aboutme.html$" />
          <conditions>
          </conditions>
          <action type="Rewrite" url="/aboutme/defaut.aspx"  />
</rule>
 
Learn More http://www.iis.net/download/URLRewrite 
Let me know,Hades666
 
0
 
Vivek ReddyCommented:
0
 
Brad HoweConnect With a Mentor DevOps ManagerCommented:
As per your last comment.
If I had multiple pages that needed this redirection what would I do.
> You would use REGEX (Regular expressions) to match the variables and pass them to the rewrite.
eg:
<rule name="Redirect *.html to www.domain.com/*/default.aspx" enabled=true" >
          <match url="^(.*).html$" />
         <conditions>
         </conditions>
         <action type="Rewrite" url="/{R:1}/defaut.aspx"  />
</rule>
The (.*) mean capture anything and the R:1 is substitute it into the rewrite. Definitly look in the IIS Manager for the URL Rewrite Module. The "TEST PATTERN" utility really helps.
Cheers, Hades666
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
cyboramaAuthor Commented:
thanks hades:

I can see how your regex logic would work if any page with a .html extension should all be redirected to the same new page (e.g. default.aspx) but I assume that regex wouldn't be the way to go if these html pages I needed redirection needed to be wired to different spots in the new file hiarchy (e.g. index.html might go to default.aspx and aboutme.html might go to default.aspx/aboutme)

Of course the above is just a scenario but the default.aspx is similiar to the index.html on linux servers and since I am going from a linux based hosting to dotnetnuke which is based on asp.net we have to use default.aspx and technically the full path to the different pieces of the hiarchy would actually include things like tabid=1 and such.

I do like your concept though with the regex in regards of bulk moving and if their was a way to utlize this when the bulk moves were wired to different pages in the new hiarchy instead of say just the home page than I would love to utilize it for sure.

Meanwhile I will take a look at your suggestions and even call or research my shared hosting provider to see what mods they are using in their iis.  I know I am on their windows 2008 server which I believe utilizes IIS 7 but the whole purpose of the web.config way of doing things would be so I could do this programatically without having to have access to the actual IIS since shared hosting control panels only give you limited control in thi respect if any.

Thanks for your help thus far however and I will try some of these things to see what I can get to work.

Take care,

cyborama
0
 
Brad HoweDevOps ManagerCommented:
Correct. Most hosting providers will install IIS URL Rewrite 2.0 and allow you to create the rules via web.config
Let me know if you have any questions.
 -Hades666
0
 
cyboramaAuthor Commented:
Hello Hades,

I was wrong I gues I am on their iis 6 which means the use of the web.config theory will not work unless I can get them to move me over.

I will give you credit for this as it has certainly been a through explanation in regards to the approach I need to do.

Thanks so much for your help,

Bo
0
 
cyboramaAuthor Commented:
very thorough explanation in regards to how to tweak web.config to do these redirects
0
 
Brad HoweDevOps ManagerCommented:
With IIS6 yuo will need to use ISAPI Rewrite which is a 3rd party application.
See "ISAPIRewrite to enable Extension-less URL Rewriting for IIS5 and IIS6 " in this article for more options.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx 
Cheers, Hades666
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.