PLS help - simple url rewrite *.html to folder

Discussion in 'Apache' started by liova, Jan 21, 2010.

  1. #1
    Hello guys
    can someone help me with an simple advice on how can I redirect all html files in website to virtual folders with the same name.
    exemple:
    /building.html -> /building/

    I have this code in .htaccess:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^([^/\.]+)/?$ $1\.html [L]
    RewriteRule ^([^/\.]+)?\.html$ /$1/ [NC,R=301] - this line doesn't work

    waiting for your advices.

    Thanks
     
    liova, Jan 21, 2010 IP
  2. ibg

    ibg Member

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #2
    Try :
    RewriteRule ^([^/\.]+)?\.html$ /%1/ [NC,R=301]
     
    ibg, Jan 21, 2010 IP
  3. liova

    liova Well-Known Member

    Messages:
    444
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    it's not working :(

    anyone else ... any ideas?
     
    liova, Jan 22, 2010 IP
  4. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #4
    your below example UN-clear or wrong!
    YOU rewrite to filename again - whereas it appears that you want to rewrite to folder ONLY without filename !!??

    below are both solutions - both are tested and work on my server


    1.
    redirect file_name.html to /folder_name/file_name.html where file_name = folder_name

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^([^/\.]+)?\.html$ /$1/$1\.html [L,R=301]


    OR

    2.
    redirect file_name.html to /foldername/ WITHOUT any html page-redirect just to folder as you specified originally:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /var/
    RewriteRule ^([^/\.]+)?\.html$ /$1/ [L,R=301]
     
    hans, Jan 26, 2010 IP