Version 2 (modified by Ana Willem, 12 years ago) (diff)


How do I redirect web users from one page to another?

There are times when you are building a new website, where the organization of the new site varies so much from the old one that you can't use the same URLS as the old site did.

It's a good thing, when possible, to use old URLs because so many people bookmark certain pages. When users with old bookmarks go to your new website, you do not want to give them an unfriendly message saying simply that the page was not found.

There are a couple things that you can do to help make users who loved your site before continue to love your site now.

The first (ONLY FOR DRUPAL USERS) is to create friendlier pages for when: 1) people try going to a page that they thought was there and isn't and 2) people try going to a page that is outside of the realm of their permissions level.

Once you create those pages, you can navigate to the 'Site configuration' section of your administrative pages and click on the option that says 'Error reporting ( In the spaces provided give the path or node number of the pages you created.

Examples of both kinds of pages: Access Denied: Page not found:

The second thing that you can do is to create what is called a redirect. A redirect tells your site that when a person clicks on a specific old link, to go to a certain page on your new site. Information and ways to configure redirects are VAST and VARIED. There are two basic ones that this wiki covers the very basics of: Redirect, and RedirectMatch.

First, you will place the code for your redirect in the 'Web configuration' section of your 'Members Control Panel'. The code for a redirect goes after the end of the close of the directory tag (</Directory>).

The first thing you want to do is put the following text there:

RewriteEngine On

This tells your configuration that you are about to give it some code for what should happen when people enter specific URL that may or may not exist on your new site. Now for what comes after this...Technically, this text is not necessary specifically for the kinds of redirects that I am showing here. It doesn't hurt to have it especially in the case that you plan to use other Redirects that require it (RewriteCond or RewriteRule).

A simple Redirect tells your site that, for a specific page, to go to another specific page. The basic redirect looks like this:

Redirect [path] URL

In this example, '[path]' refers to the part of the URL that comes after the 'root' of your site. So for example the path of '' is '/this/that/etc'. The path represents the address that you want to redirects users from. So if a user has bookmarked 'http://mysite/this/path' and you want them to go to '', the full redirect will look like this:

Redirect /this/path

If you wanted to take them to a completely different site, you could do that also:

Redirect /this/path

There are a lot of ways to do this and to use this function. If you want more, you can google it.

The other kind of Redirect involves a 'wildcard'. A wildcard is usually represented by an asterisk '*' and generally means 'anything'. It's like in poker when I play a wildcard, I can make that card be anything I want.

The reason that it becomes useful is that the standard website has the following structure:

If you wanted to redirect everypage that had a path that started with'/firstpart/' then you will need a wildcard to do that. It prevents you having to create a redirect for every single webpage on your old site.

The simplest RedirectMatch is written like this:

RedirectMatch 301 ^/firstpart/(.*)$

So in this case, it is telling the configuration that when a user wants to go to the page:, or, or, or

to send those users to:

This is, again, a very condensed tutorial that is designed to just tell you one way to do things, and not in a way that teaches you deeper principles of these functions. There are other ways to use them as well. Some sites that go into this in more detail include: or, or,

The option that we did not discuss here is to use an .htaccess file to redirect folks. This isn't recommended and the reasons why is in this ticket: