Submit Your Article Forum Rules

Results 1 to 6 of 6

Thread: 301 redirects on windows server

  1. #1
    Member julien_simon's Avatar
    Join Date
    Dec 2010
    Location
    Vancouver
    Posts
    76

    301 redirects on windows server

    Hey guys,

    Do you know what the best way is to do a 301 redirect from a www. version to a non www.version without using htaccess? I have a site on a windows machine.

    A programmer friend suggested:
    1. Convert all .htm pages to .php pages

    2. Convert all internal links to point to .php pages not .htm pages

    3. Add this php code to the top of every page (before the <doctype> and <html> tags):

    if (substr($_SERVER['HTTP_HOST'], 0, 4) === 'www.') {

    header('Location: http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : ''). '://' . substr($_SERVER['HTTP_HOST'], 4) . $_SERVER['REQUEST_URI']);

    exit;

    }

    but she is not willing to do that. Moreover, she is on a windows machine so it may not even work.

    Any ideas, suggestions?

  2. #2
    On a Unix machine, adding that code to every page is silly... you would just add something different to the .htaccess file:
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/ 
    RewriteRule ^index\.html$ http://www.domain.com/ [R=301,L]
    And this will route the domain.com and /index.html to www.domain.com

    On Windows she's dealing with IIS which can certainly run PHP so adding the above should work, but best option is here: http://serverfault.com/questions/225...-www-in-iis7-5

  3. #3

    Thumbs up The easiest and most effective way ..

    Would be to modify your Web.config in the root of the application and utilize the powerful IIS rewrite rules capabilities.
    Something similar to:

    <rule name=”Remove WWW prefix” >
    <match url=”(.*)” ignoreCase=”true” />
    <conditions>
    <add input=”{HTTP_HOST}” pattern=”^www\.domain\.com” />
    </conditions>
    <action type=”Redirect” url=”http://domain.com/{R:1}”
    redirectType=”Permanent” />
    </rule>
    </rules></rewrite>


  4. #4
    Member julien_simon's Avatar
    Join Date
    Dec 2010
    Location
    Vancouver
    Posts
    76
    thanks for the suggestions! I'll do some testing and share the results.

  5. #5
    Moderator Tiggerito's Avatar
    Join Date
    May 2004
    Location
    Adelaide, Australia
    Posts
    550
    @NexusSoft suggestion requires a newer version of IIS (7 I think) and the Routing Module needs to be enabled.

    If it's an older IIS then you need to install an external tool that mimics .htaccess Here's one:

    http://iirf.codeplex.com/
    by Tony McCreath (Tiggerito)
    owner of Web Site Advantage

  6. #6
    WebProWorld MVP mjtaylor's Avatar
    Join Date
    Dec 2003
    Posts
    6,237
    Not my bailiwick, but we do have a nice sticky on this: http://www.webproworld.com/webmaster...evention-Guide.
    SEO Friendly Premium Web Directory - Submit Now| Need to write a love letter to Google? I'm an SEO Copywriter who knows Search Smart Design®. | Travel Gypsy in Key West.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •