301 redirect on IIS To Fix Domain Issues In Windows

Redirecting Requests to Files, Directories, or Programs (IIS 6.0)
You can redirect requests for files in one directory to a different directory, to a different Web site, or to a file in a different directory. When the browser requests the file from the original URL, the Web server instructs the browser to request the page from the redirected URL.

An advanced capability of the redirect method allows you to redirect all requests for files in a particular directory to a program. Generally speaking, you should also pass any parameters from the original URL to the program, which you can do by using redirect variables.

iis redirect Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /User:Administrative_AccountName“mmc %systemroot%\system32\inetsrv\iis.msc”.

>Procedures

To redirect requests to another directory or Web site

1.

In IIS Manager, expand the local computer, right-click the Web site, virtual directory, or directory within a Web site to which you want to add a redirect, and click Properties.

2.

Click the Home Directory, Virtual Directory, or Directory tab.

3.

Under The content for this resource should come from, click A redirection to a URL.

4.

In the Redirect tobox, type the path to the destination directory or the URL of the Web site. For example, to redirect all requests for files in the /Catalog directory to the /NewCatalog directory on another Web site, type http://sitename/NewCatalog. The redirect must be to a fully qualified URL.

5.

Set the required flags as specified below, and then click OK. More than one flag is allowed.

To redirect all requests to a single file

1. In IIS Manager, right-click the Web site or directory, and click Properties.

2.

Click the Home Directory, Virtual Directory, or Directory tab.
3. Under The content for this resource should come from, click A redirection to a URL.
4. In the Redirect to box, type the URL of the destination file. The redirect must be to a fully qualified URL.
5. Under The client will be sent to, select The exact URL entered above check box to prevent the Web server from appending the original file name to the destination URL.

6.

Click OK.

You can use wildcards and redirect variables in the destination URL to precisely control how the original URL is translated into the destination URL.

To redirect requests to a program

1. In IIS Manager, right-click the Web site or directory, and click Properties.
2. Click the Home Directory, Virtual Directory, or Directory tab.
3. Under The content for this resource should come from, click A redirection to a URL.
4. In the Redirect to box, type the URL of the program, including any redirect variables needed to pass parameters to the program.For example, to redirect all requests for scripts in a Scripts directory to a logging program that records the requested URL and any parameters passed with the URL, type /Scripts/Logger.exe?URL=$V+PARAMS=$P. $V and $P are redirect variables.
5. Under The client will be sent to, select The exact URL entered above check box to prevent the Web server from appending the original file name to the destination URL.
6. Click OK.

Redirect Reference (IIS 6.0)

Redirecting a client request is one way to ensure that users get the correct page, if your site is under construction or has changed identity. You can redirect client requests to a directory on the same Web server or to a different URL.


H3>Configuring URL and Wildcard Redirection

You can configure redirection to a URL and wildcard redirection programmatically. Redirection variables and flags allow you to specify targets and behavior by changing the HttpRedirectmetabase property.

The following example shows the format of a simple redirection string.

http://DestinationURL[,Flag[s]]

Where DestinationURL can include the following redirect variables to pass portions of the original URL with the destination URL. You can use more than one variable in a single redirection string.

Variable Description Example

$S

Passes the suffix of the requested URL to the new URL. The suffix is the portion of the original URL that remains after the redirected URL is substituted.

If the EXACT_DESTINATION flag is not set, the resulting destination URL will have the name of the requested file appended as a folder name, as well as the file name itself.

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following exact URL:

http://fabrikam/NewScripts$S

A new request for the following URL:

http://fabrikam/Scripts/Program.exe

Would be redirected automatically to the following URL:

http://fabrikam/NewScripts/Program.exe

$P

Passes parameters (such as querystring parameters) in the original URL to the new URL, without the question mark (?).

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following URL:

http://fabrikam/NewScripts$P

A new request for the following URL:

http://fabrikam/Scripts/File.asp?var1=5&var2=6

Would be redirected automatically to the following URL:

http://fabrikam/NewScriptsvar1=5&var2=6

$Q

Passes parameters (such as querystring parameters) in the original URL to the new URL, including the question mark (?).

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following exact URL:

http://fabrikam/NewScripts$S$Q

A new request for the following URL:

http://fabrikam/Scripts/File.asp?var1=5&var2=6

Would be redirected automatically to the following URL:

http://fabrikam/NewScripts/File.asp?var1=5&var2=6

$V

Passes the requested URL, without the server name and without any parameters. To include parameters, use the $P or $Q variable with the $V variable.

If the EXACT_DESTINATION flag is not set, the resulting destination URL will have the name of the requested file appended as a folder name, as well as the file name itself.

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following exact URL:

http://contoso$V

A new request for the following URL:

http://fabrikam/Scripts/File.asp

Would be redirected automatically to the following URL:

http://contoso/Scripts/File.asp

Redirection Using Wildcards

You can use redirect wildcards to match any number of characters in the original URL. Begin the destination URL with an asterisk (*) and a semicolon (;), and separate pairs of wildcard characters and destination URLs with a semicolon. The following example shows the format of a redirection string that uses wildcards.

*; Wildcard1; Destination1[; Wildcard2; Destination2][, Flags]

Where WildcardN can include an asterisk (*) to match any number of characters in the original URL and pass them to DestinationN by using the $0 through $9 variables defined in the following table.

“Variable” “Description” “Example”
$0 through $9 Passes the portion of the requested URL that matches the indicted wildcard character. Wildcards must start at $0 for each Wildcard;Destination set. The EXACT_DESTINATION flag must be appended to the redirection string. If the virtual directory that is mapped to the following Web site:http://fabrikam/Scriptsis configured with the following redirection string:*; /Scripts/*_in.asp; /NewScripts/$0.dll; /Scripts/*_out.asp; http://contoso/NewScripts/$0.dllA new request for the following URLs:http://fabrikam/Scripts/data_in.asphttp://fabrikam/Scripts/data_out.aspWould be redirected automatically to the following respective URLs:http://fabrikam/NewScripts/data.dll

http://contoso/NewScripts/data.dll

!

Does not allow a redirect.

This variable is useful when you want to exempt files or subdirectories from redirection when a parent directory is configured to be redirected.

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected, but the following Web site:

http://fabrikam/Scripts/Commerce/Accounts

needs to be exempt, programmatically set the redirection string for the exempted folder to the following

*;!

For example, to redirect all requests for /Scripts/Filename.stm to a single file called Default.stm, and to redirect all requests for /Scripts /Filename.htm to a single file called Default.htm, use the following redirect request for the /Scripts virtual directory:

*;Filename.stm;/Default.stm/Filename.htm;/Default.htm

Using Redirection Flags

The following flags augment redirect strings of either URL or wildcard format. More than one flag is allowed. Flags are appended programmatically to the redirection string in HttpRedirect, or configured by selecting check boxes in IIS Manager.

Flag User Interface Check Box Description
EXACT_DESTINATION The exact URL entered above Indicates that the value provided for the destination should be considered an absolute target location.
CHILD_ONLY A directory below this one Alerts IIS that redirection should occur only once because the destination is in a subdirectory of the original URL. This flag avoids loops. Also, this flag instructs IIS to redirect requests only if they are to subfolders or files of the original URL.
PERMANENT A permanent redirection for this resource Indicates that this redirection is permanent for this resource.
TEMPORARY Clear the A permanent redirection for this resource check box” Indicates that this redirection is temporary for this resource.

How to Move Pages on Windows Servers

Most Windows servers will be running Microsoft’s Internet Information Server (IIS), and pages can be moved using ASP or ASP.NET code, depending on what the server is running (ask your web host). To move a page using ASP, set up the page at its new location then place the following code at the top of the old page:

Move a page using ASP
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.domain.com/new-page.asp”
%>

Make sure that code is the first thing at the top of the page. As for the rest of the page, you can either remove its content or leave it—search engines won’t care one way or another. However, some of your human visitors (remember them?) will have auto-redirection turned off in their browsers.

This means they won’t be redirected, and will see the old page instead of the new one. So you may want to include a link to the new page, along with a short message telling them that the page they’re on is outdated and has been moved to a new location.

Similarly, you can move a page using ASP.NET, but beware there’s currently a glitch in the way ASP.NET 2 handles redirects. That glitch should be fixed soon. To redirect a page using ASP.NET, set up the new page at its new location, then place the following code at the top of the old page:
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(“Location”,”http://www.domain.com/new-page.asp”);
}
</script>

For both of these redirects leave the old pages in place for as long as possible, since it usually takes several months for search engines to switch over to only crawling the page at its new location. They’re a bit slow that way.

Get Found Now – a division of: On Top Of It, Inc

Use mod_rewrite To Deal With Database Driven URLs

Perhaps you’re familiar with that little bit of Apache server magic known as mod_rewrite. You may already know that it can take your ugly, unwieldy, dynamic URLs that look like:

http://yoursite.com/index.php?item=muumuu&color=blue&size=large

…and turn them into static-looking URLs that are easier on the eyes:

http://yoursite.com/muumuu/blue/large

or even:

http://yoursite.com/m/b/l

Clearly, such rewritten URLs offer a more friendly appearance to real humans. They’re more descriptive and they’re easier to remember. What’s more, they tend to be about 30% to 50% shorter than URLs containing database driven dynamic characters and, on a super-large site, you may even save a little bandwidth.

But the real question is:

Do rewritten URLs make a difference when it comes to getting your pages indexed and ranked higher in the search engines?

Well, the answer is, they do make a difference. In fact, rewritten URLs can make a big difference.

While it’s true that Google has come a long way in parsing dynamic pages, just because the Google spider isn’t choking on your dynamic URLs anymore doesn’t mean it isn’t avoiding indexing them, and it also doesn’t mean it isn’t still giving preference to static URLs.

Google will accommodate dynamic URLs to a point, but it doesn’t like them. We’ve seen dynamic sites go from 2,000 pages indexed by Google to over 10,000 pages indexed after using mod_rewrite to switch from dynamic to static-looking URLs. In addition, these pages get indexed more quickly and more frequently than their dynamic counterparts.

How can I tell if mod_rewrite is set up on my server?
The easiest way to tell if you have mod_rewrite installed is simply to ask your system administrator.If you are the system administrator, or if you’re looking for some of the more technical details about getting mod_rewrite running, please have a look at the official mod_rewrite documentation.

In our experience, search engine spiders always prefer static URLs over dynamic URLs, and if you have a large, dynamic site that you want to get fully – as well as quickly and frequently – indexed by the search engines, then rewriting your dynamic URLs is a must.

A Simple Example

Despite what you may have heard, it’s actually fairly easy to get started with some basic URL rewriting. Here’s an example:

First, you’ll need to edit (or create if it doesn’t already exist) an .htaccess file in whichever directory you will be rewriting your URLs. An .htaccess file (note the period at the beginning of the file name) is an Apache server configuration file that lets you make changes to your server setup on a per-directory basis. For more info on creating and editing your .htaccess file, check out the official .htaccess guide, as well as this excellent tutorial.

Now, say you have a dynamic URL that looks like:

http://www.yoursite.com/index.php?item=muumuu&color=blue

…and you would like to have a more search engine (and user) friendly URL such as:

http://www.yoursite.com/muumuu/blue

To accomplish this, simply add the following two lines to your .htaccess file:

RewriteEngine On
RewriteRule muumuu/blue index.php?item=muumuu&color=blue

(Note: there is a space between the words blue and index.php in the above line)

The first line turns the mod_rewrite engine on. The second line consists of three parts:

  1. RewriteRule — This part lets the server know that you’re about to specify a rule to rewrite your URL.
  2. muumuu/blue — This is the way you want the dynamic part of your URL to appear to spiders and other visitors to your web site.
  3. index.php?item=muumuu&color=blue — This is the way the dynamic part of your URL appears currently.

And voilà! …you’ve just hidden your dynamic URL from any search engine spider.

Not so fast, there, pardner…

“Just a minute?” we hear you saying,

“This is all well and good for someone who has just a few dynamic pages, but I have over 10,000 dynamically generated pages! It could take me weeks to write all those rules.”

Right you are, and this is where the voodoo magic of regular expressions comes in.

The term regular expression refers to a type of miniature programming language which is extremely effective at recognizing and matching patterns in text. You can find a nice intro here.

Unfortunately, the awesome power of regular expressions comes with a fairly steep learning curve. Listed below, however, are some pre-fabricated formulas that should apply to many sites. These should help you get started with mod_rewrite even if you’re a regular expression novice.

By the way, you can get pretty far along the right path if you just know the following details about regular expression syntax:

. Matches any one character
? Matches the preceding character zero or one times
* Matches the preceding character zero or more times
+ Matches the preceding character one or more times
^ Matches the beginning of a line
$ Matches the end of a line

Now, let’s go back to our first example, but this time, instead of writing a specific rule for muumuu and blue, let’s make our rule flexible enough to handle any word as a value for the variables item and color in our dynamic URL. Open up that .htaccess file again and add the following:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?item=$1&color=$2

Looks like gibberish, doesn’t it?

Don’t worry, we can handle it. Let’s walk through it line-by-line:

  1. The first line, as we already know, simply turns on the mod_rewrite engine.
  2. The second line contains the phrase:

    Options +FollowSymlinks

    This line, primarily for those servers running Windows operating systems, tells the server to follow symbolic links. If you’re on a Unix or Linux-based server, then symbolic links are already enabled, but it doesn’t hurt to include this line in your .htaccess anyway – just in case they’ve been turned off.

  3. Next we come to the third line:

    RewriteBase /

    This sets the base URL. Setting it to “/” is usually the same as setting the base to your domain root which, in our example, is http://www.yoursite.com/.

    It’s important to understand that when we rewrite URLs we are rewriting the stem, not the root. In other words, when mod_rewrite rewrites a URL such as:

    http://www.yoursite.com/index.php?item=muumuu&color=blue

    … it will modify the part of the URL that looks like

    index.php?item=muumuu&color=blue

    while ignoring the part that looks like http://www.yoursite.com/.

  4. The fourth line consists of three parts:1) RewriteCond — This is the rewrite condition. In other words, this line needs to be true in order for any URL rewriting to occur. If this condition is not satisfied, the immediately following rewrite rule is ignored and mod_rewrite continues on processing any rules after it.2) %{REQUEST_URI} — This is an Apache-specific variable which refers to the page that is being requested. In the case of the URL http://www.yoursite.com/index.php?item=muumuu&color=blue the page being requested is index.php.3) !index.php — In English, this is equivalent to saying “is not index.php”. In regular expressions, the “!” character is also know as the “not” character.So what this line really says is “if the page being requested is not index.php, then process the next mod_rewrite rule”. We need to make sure that we don’t run mod_rewrite if index.php is called without any arguments, because this could leave us stuck in an infinite loop where we are just replacing index.php with itself over and over again.
  5. The last line also consists of three parts:1) RewriteRule — We already know that this part lets the server know that you’re about to specify a rule to rewrite your URL.2) ^([^/]+)/([^/]+)/?$ — This is the challenging part (No, it’s not a complicated smiley). It’s a regular expression that introduces something we haven’t seen before – namely, the “[ ]” symbols, which define a character class. A character class is a way to separate characters from each other in a regular expression. The rules are slightly different within a character class, namely, the “^” symbol no longer means “beginning of line”, but instead means “not” – similar to the “!” symbol we saw earlier.3) The other new concept we are seeing is the parenthesis. This is not only a grouping technique but also has the added power of being a back reference. What this means is that any text that matches an expression between parenthesis can be saved and referred to later by the symbols $1, $2, $3, and so forth. In other words, the text matching inside the first pair of parenthesis is placed in the variable $1, the text matching inside the second pair of parenthesis is placed in the variable $2, and so on.We can break this regular expression apart piece-by-piece:
    ^ Look for the beginning of a line.
    ( Opening parenthesis indicating the start of a back reference.
    [ Opening bracket indicating the beginning of a character class.
    ^ "Not" symbol (since it's inside a character class).
    / This represents an actual forward slash, such as you would find in a URL.
    ] Close the character class.
    + Match the preceding character or group of characters one or more times.
    ) Close the back reference.

    So what the expression ^([^/]+) really says is “find the beginning of a line, followed by as many characters as you can find that are NOT forward slashes, and store them in the variable $1 for later use”.

    If you have a line like:

    muumuu/blue

    …then the expression ^([^/]+) would have the effect of storing the word muumuu in variable $1.

    Back to our regular expression:

    / Look for a forward slash following the last chunk of text we matched.
    ([^/]+) We explained what this means earlier. It matches the word blue in the example above, and stores it in the variable $2.
    / Followed by another forward slash.
    ? This question mark means “match the preceding character 0 or 1 times.” Since it comes directly after the last forward slash, this means that the last forward slash is optional (i.e. it can show up once, or not at all).
    $ Finally, look for the end of a line.

    Now let’s look at the last part of line three, which looks like:

    /index.php?item=$1&color=$2

    This is the way your dynamic URL looked originally, except that in the place of the back reference variables $1 and $2 you will actually find your current GET variables (such as muumuu and blue). What will happen is the text that was captured by the back references in the regular expression will be inserted into your dynamic URL at the point where the $1 and $2 variables are found.

    When a request is made for a page like:

    http://www.yoursite.com/muumuu/blue

    …mod_rewrite will recognize that this URL is actually pointing to the address:

    http://www.yoursite.com/index.php?item=muumuu&color=blue

    …and will send your visitor (be they human or search engine spider) to the correct address, without them ever seeing what goes on behind the scenes. This is part of the beauty of mod_rewite. The URL is not being redirected – it is actually being rewritten on the server by mod_rewrite. No visitor to your site will ever see your dynamic URLs, or even be able to tell that they ever existed.

We Never Said It Was Easy

While it’s true this is a rather complicated example, and especially so if you’re new to regular expressions, our goal here is to give you some practical examples that can be applied to real life situations instead of the “toy” examples that are often used in most tutorials.

Additionally, the example we’ve used can easily be modified for any number of variables. For example, if your dynamic URLs have between one and three variables, depending on the circumstance:

http://www.yoursite.com/index.php?item=muumuu

http://www.yoursite.com/index.php?item=muumuu&color=blue

http://www.yoursite.com/index.php?item=muumuu&color=blue&size=large

… you could add the following to your .htaccess:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/?$ /index.php?item=$1
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?item=$1&color=$2
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?item=$1&color=$2&size=$3

… to get URLs that looks respectively like:

http://www.yoursite.com/muumuu/

http://www.yoursite.com/muumuu/blue

http://www.yoursite.com/muumuu/blue/large

Caveat emptor (A warning):

Bear in mind that rewriting your URLs increases the amount of processing done by your server, so your pages might load slightly slower, and, if you have a really high-traffic site, the load on your server might be unacceptably high.

The danger with mod_rewrite is that the search engine spiders won’t realize that you have a dynamically generated site, so they will crawl your site just as fast as they would a static site. Your system may be overwhelmed and you could experience a server slowdown or even crash if you don’t have adequate processing power.

We highly recommend that you experiment with mod_rewrite on a test server before taking it live with your main site. We have done our best to make sure that these examples work in a variety of circumstances but, considering all the vagaries of different server configurations, you may find that rewrite rules that work on our servers might not work on yours.

Voodoo?

Whether or not you agree with the fellow who commented: “this is damn cool voodoo, but voodoo nonetheless,” we consider it a valuable tool – especially useful for large, dynamically-generated sites.

Knowing that Google, for one, loves large sites and knowing that you can double or quadruple (or more) the number of pages that search engines will index, that should be enough incentive to, at least, experiment with mod_rewite. The reward waiting in the wings is an almost certain boost in your site’s overall search engine rankings once you get all of your database-driven dynamically-generated pages indexed and then working together in sync.

Get Found Now – a division of: On Top Of It, Inc

Search Engine Optimization ABCs and FAQs

META-TAGS
META-TAGS are the part of your website’s HTML code that allows a search engine to easily identify your site’s content. In the infancy of search engine optimization, meta-tags were the primary vehicle marketers and coders used for attracting search engine traffic. Today, search engines examine more than meta-tags; they take into account site content, internal link structure, and link popularity. Yet nonetheless, meta-tags remain the cornerstone of a successful search engine marketing program. Three primary meta-tags help search engines determine the relevance of a website for a specific search phrase: the title tag, the description tag, the keyword tag.

The TITLE TAG.
First, there is the Title Tag. Your Title Tag must describe exactly what your webpage contains. It has to contain the keywords — descriptive words that describe what your website offers or does — for which you hope to be found. This Title Tag will be the first thing your user sees so it must be clear and simple to read.Keep the Title Tag 70 characters or less. Make sure that it employs words and phrases that describe the content of the page as accurately as possible. Make each and every Title Tag is unique and relevant, that every word in this tag is contained somewhere in the tag’s page.

TITLE TAG HINTS.

Designing Search-Friendly Web Pages:

There are two important points to remember about search engines:

1. The first is…The quality of your site counts. Search engines make their money through advertising. Showing ads to their users is their profit model, and the more users they have, the more money they make. The way search a search engine gets more users is by giving them the best search results. This means that if your site is the most useful site to customers in your category, then search engines want to rank you highly. Indeed, their livelihood depends on it.

2. The second thing to remember is…Search engines are computer programs. More precisely, search engines run a program called a spider than downloads your web pages, reads the text and links on those web pages, and decides what to do with your pages based on that information. This is known as crawling. Search engine spiders are computer programs that crawl web pages.

Employ a Flat Directory Structure
In general, the flatter your site’s directory structure, the better your chances of getting more of your pages spidered. In other words, pages that are several sub-directory levels deep will often get spidered less frequently. For example, consider the depth of the web page at the following URL:

http://www.yoursite.com/content/articles/2005/05/pages.htm

Closer inspection revels that the file page.html is six directory levels deep.

A page that deep should generally not expect to be easily indexed or rank highly in any search engine. Expectations maybe made for popular sites with lots of incoming links, but any web page buried that deep puts itself a ranking disadvantage.

It is not uncommon to use directories to organize the structure of a site. That is because a flat directory structure-one that places all the pages only tow or three levels deep-is very difficult to logically organize. If the structure of your site dictates that you must utilize deep sub-directories, then it becomes even more important to utilize a strategically placed site map.

Use a Site Map
A site map is a web page that links to every other page within your site. By creating a good site map and linking to from your homepage, you ensure that each [age on your site is only one click away fro your site map and only two clicks away from your homepage. This is the optimum structure in terms of making web pages easy for the search engine spider to find.

As you know, search engines spiders find new pages by following links fro the pages that are already in their index. Thus, if you want a spider to crawl a web page, you have to make sure that it’s linked to from a page the search engine already knows about.

However, unless you have a very small site, linking to all your pages from your homepage would look messy and unprofessional to your customers. The site map allows us to accomplish our objective of getting all of our pages indexed without cluttering our home page with links. By placing a link on your homepage to the site map, and then a link form the site map to all of the rest of your important pages, you make all your site’s pages easy to find and index.

The search engines themselves will tell you to use a site map to ensure that all your web pages get indeed. In fact, Google has its own site map program. Our SEO Tune Up covers the basics of good Search Engine Optimization practices.