Saturday, August 21, 2010

.htaccess - DirectoryIndex with rewrite

I was looking for a way to not only set the default landing page for a directory, but also get that page name to show in the browser's URL area (basically with rewrite). Googling and browsing through the Apache manual didn't seem to give an answer, so here's what I did...

RewriteRule ^folder/$ /folder/defaultpage [R]

Seems obvious, but it was an "Aha!" moment for me. The folder path would be relative to root - if someone tries to access the folder, redirect them to the page within the folder. Virtually the same length as DirectoryIndex, but with a twist - enjoy!

4 comments:

  1. Thanks to share this nice post.
    I hope, it help to many as it has to me.

    ReplyDelete
  2. This is a wonderful post and I like it. I am looking forward on your nice blog. Thank you for sharing.



    Shasing

    ReplyDelete
  3. Congratulation!

    Axel from Paris, France

    ReplyDelete