Recipe 22.7. Redirecting URLs to a New Directory

 < Day Day Up > 

22.7.1 Problem

You've just given your web site a massive overhaul. It was a cluttered, disorganized mess, so you rebuilt it from the ground up. But now all the links are different, so all those bookmarks visitors have made to your pages, and all those links in online articles and search engines are useless. What can you do about it?

22.7.2 Solution

Add Rewrite directives to httpd.conf. This example redirects the old URLs to the new ones:

RewriteEngine on RewriteRule ^/olddir/(.*)$ /newdir/$1

In plain English, this means that http://www.bratgrrl.com/olddir/, and every file and directory that follow olddir/, will be redirected to http://www.bratgrrl.com/newdir/.

22.7.3 Discussion

This is a good basic Rewrite rule that takes care of one of the most common redirection needs. As you can see, if you're moving entire directories at a time, it's fairly simple. If you have bales of individual files going to different locations, you have a lot of rules to write.

22.7.4 See Also

  • The URL Rewriting Guide (http://localhost/manual/misc/rewriteguide.html)

     < Day Day Up > 


    Linux Cookbook
    Linux Cookbook
    ISBN: 0596006403
    EAN: 2147483647
    Year: 2004
    Pages: 434

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net