Redirect all files reference permanently from old dir to new dir

Discussion in 'Apache' started by northwest, Feb 18, 2008.

  1. #1
    Hi,

    I want to redirect all the old file reference from old directory to new dir.

    for ex.

    I want the following file references:

    domain.com/old_dir/file1.html
    domain.com/old_dir/file2.html
    domain.com/old_dir/file3.html

    to the following

    domain.com/newdir/search.php?item=file1
    domain.com/newdir/search.php?item=file2
    domain.com/newdir/search.php?item=file3

    If I cannot get the above then at least I want the following:

    domain.com/old_dir/file1.html
    domain.com/old_dir/file2.html
    domain.com/old_dir/file3.html

    to be redirected to the following:

    domain.com/newdir/


    How do I accomplish this?

    Thanks!
     
    northwest, Feb 18, 2008 IP
  2. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure about what kind of redirect you want. I assume that all what you need is to rewrite the URL's without any redirect.
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^old_dir\/(.*)\.html$ /newdir/search.php?item=$1 [L]
    
    Code (markup):
    Jean-Luc
     
    Jean-Luc, Feb 19, 2008 IP
  3. northwest

    northwest Peon

    Messages:
    277
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This did not work. What type of redirects are there?

    The old_dir does not exist but there are URLs in the search engines and that's why I want the visitors to be redirected to the new URL.
     
    northwest, Feb 19, 2008 IP
  4. LoCo

    LoCo Well-Known Member

    Messages:
    232
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    hi

    Redirect 301 /oldpage.html http://www.example.com/newpage.html
    Code (markup):
    this should do the trick
     
    LoCo, Feb 19, 2008 IP
  5. northwest

    northwest Peon

    Messages:
    277
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It is actually many pages from old dir needs to be redirected to specific new dir pages. Here's an example;

    The following pages:

    domain.com/old_dir/file1.html
    domain.com/old_dir/file2.html
    domain.com/old_dir/file3.html

    should be redirected to the following pages

    domain.com/newdir/search.php?item=file1
    domain.com/newdir/search.php?item=file2
    domain.com/newdir/search.php?item=file3
     
    northwest, Feb 19, 2008 IP
  6. LoCo

    LoCo Well-Known Member

    Messages:
    232
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Well then just do the same as above just for every page you need it for

    example

    Redirect 301 /old_dir/file1.html domain.com/newdir/search.php?item=file1
    Redirect 301 /old_dir/file2.html domain.com/newdir/search.php?item=file2
    Redirect 301 /old_dir/file3.html domain.com/newdir/search.php?item=file3
    Code (markup):
     
    LoCo, Feb 19, 2008 IP
  7. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    To redirect a bunch of old URL's to new one's, I would use this:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^old_dir\/(.*)\.html$ http://www.example.com/newdir/search.php?item=$1 [L,R=301]
    
    Code (markup):
    Jean-Luc
     
    Jean-Luc, Feb 20, 2008 IP