Apache mode_rewrite question

Discussion in 'Apache' started by daringtakers, Jan 6, 2009.

  1. #1
    Please help me in achieving following.

    How can I redirect

    /directory1/* to /directory2/*

    Example

    /directory1/a.html should be redirected to /directory2/a.html
    and
    /directory1/b.html should be redirected to /directory2/b.html

    Q2. How can i redirect the directory root to the index.html

    Example

    /directory1/ should be redirected to /directory1/index.html


    Thanks
     
    daringtakers, Jan 6, 2009 IP
  2. thuankkk

    thuankkk Active Member

    Messages:
    503
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Q1:

    /directory1/.htaccess
    
    RewriteEngine on
    RewriteRule ^(.*)$ /directory2/$1 [R, L]
    
    Code (markup):
    Q2:

    /directory1/.htaccess
    
    RewriteEngine on
    RewriteRule ^/$ index.html [R, L]
    
    Code (markup):
     
    thuankkk, Jan 6, 2009 IP
  3. Topper

    Topper Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am somewhat new at this. Where do you put the code? Oh, sorry, I should have looked closer. It's in the .htaccess file.
     
    Topper, Jan 6, 2009 IP
  4. daringtakers

    daringtakers Well-Known Member

    Messages:
    808
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Thanks thuankkk for replying...

    But I cant use the rule you suggested. Because directory1 and directory 2 are not physical directory present in file system, it is drupal aliases (rewritten path). so i cant put the suggested rule into .htaccess file under directory1 or directory2. it has to go inside my public_html directory. in this case these rules are not valid.

    Sorry for confusion.
     
    daringtakers, Jan 6, 2009 IP