Changes between Version 1 and Version 2 of faq/domain/redirect-web-users


Ignore:
Timestamp:
Feb 4, 2009, 1:07:01 PM (15 years ago)
Author:
Ana Willem
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • faq/domain/redirect-web-users

    v1 v2  
    11= How do I redirect web users from one page to another? =
     2
     3There 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.
     4
     5It'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.
     6
     7There are a couple things that you can do to help make users who loved your site before continue to love your site now.
     8
     9The 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.
     10
     11Once 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 (mysite.com/admin/settings/error-reporting). In the spaces provided give the path or node number of the pages you created.
     12
     13Examples of both kinds of pages:
     14Access Denied: http://schr.org/naughty
     15Page not found: http://schr.org/woops
     16
     17The 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.
     18
     19First, 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>).
     20
     21The first thing you want to do is put the following text there:
     22
     23{{{
     24RewriteEngine On
     25}}}
     26
     27This 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).
     28
     29A simple Redirect tells your site that, for a specific page, to go to another specific page. The basic redirect looks like this:
     30
     31{{{
     32Redirect [path] URL
     33}}}
     34
     35In this example, '[path]' refers to the part of the URL that comes after the 'root' of your site. So for example the path of 'http://mysite.com/this/that/etc' 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 'http://mysite.com/another/path', the full redirect will look like this:
     36
     37{{{
     38Redirect /this/path http://mysite.com/another/path
     39}}}
     40
     41If you wanted to take them to a completely different site, you could do that also:
     42
     43{{{
     44Redirect /this/path http://othersite.com/another/path
     45}}}
     46
     47There are a lot of ways to do this and to use this function. If you want more, you can google it.
     48
     49The 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.
     50
     51The reason that it becomes useful is that the standard website has the following structure:
     52
     53{{{
     54http://mysite.com/firstpart
     55http://mysite.com/firstpart/secondpart
     56http://mysite.com/firstpart/secondpart/thirdpart
     57http://mysite.com/firstpart/secondpart/thirdpart/etc
     58}}}
     59
     60If 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.
     61
     62The simplest RedirectMatch is written like this:
     63
     64{{{
     65RedirectMatch 301 ^/firstpart/(.*)$ http://mysite.com/other_firstpart
     66}}}
     67
     68So in this case, it is telling the configuration that when a user wants to go to the page:
     69
     70{{{
     71http://mysite.com/firstpart, or
     72http://mysite.com/firstpart/secondpart, or
     73http://mysite.com/firstpart/secondpart/thirdpart, or
     74http://mysite.com/firstpart/secondpart/thirdpart/etc...
     75}}}
     76
     77to send those users to:
     78
     79{{{
     80http://mysite.com/other_firstpart.
     81}}}
     82
     83This 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:
     84
     85
     86http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectmatch or,
     87http://www.baldwinit.com/redirectmatch-with-wildcards.html or,
     88http://www.askapache.com/htaccess/301-redirect-with-mod_rewrite-or-redirectmatch.html
     89
     90
     91The 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:
     92
     93https://support.mayfirst.org/ticket/720