Solved

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

Posted on 2010-09-23
8
785 Views
Last Modified: 2013-12-08
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
0
Comment
Question by:cyborama
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:Vivek Reddy
ID: 33751254
0
 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 total points
ID: 33754845
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
 
LVL 30

Assisted Solution

by:Brad Howe
Brad Howe earned 500 total points
ID: 33754910
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 MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:cyborama
ID: 33757597
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
 
LVL 30

Expert Comment

by:Brad Howe
ID: 33757845
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
 

Author Comment

by:cyborama
ID: 33781669
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
 

Author Closing Comment

by:cyborama
ID: 33781691
very thorough explanation in regards to how to tweak web.config to do these redirects
0
 
LVL 30

Expert Comment

by:Brad Howe
ID: 33781732
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

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question