Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite question & index files



3:54 pm on Jul 26, 2003 (gmt 0)

10+ Year Member

Can someone point me to info on this? THis is a notoriously difficult problem I can't figure out.

How to rewrite index.html to another file when Apache does an index check BEFORE the rewrite.


RewriteEngine on
RewriteRule ^index\.html$ rewrite\.html [L]

Surfing to this directory


You don't have permission to access /rewritedir/ on this server.

Because there is no index.html file in the directory since what we want to do is rewrite any requests to it FIRST to rewrite.html

Anybody solve this problem?


9:53 pm on Jul 26, 2003 (gmt 0)

10+ Year Member

actually, its not because there's no index.html file in there... you are getting that message because you are not allowed to see any files in there... that's the way i'm reading it, anyway...

also, there is a difference between




your rewriterules need to take that into account, as well...

FWIW: this particular topic seems to be quite regular in this forum... i know that i've read and participated in several of them in the past month or two... sadly, i can't remember which ones they are and i actually wanted to go ahead and at least get you some answer pointing you in the proper direction(s)...


10:23 pm on Jul 26, 2003 (gmt 0)

10+ Year Member

If I rightly recollect mod_rewrite rewriter URL to filename, not filename to filename.

Does adding the following line help?

RewriteRule ^$ rewrite\.html [L]


11:24 pm on Jul 26, 2003 (gmt 0)

10+ Year Member


i've been doing some hunting and hopefully can now point you in a more refined direction...

first, have you looked at Introduction to mod_rewrite [webmasterworld.com]?

also, try it something like this... (taken in part from the above link)

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^index\.htm[l]$ [NC]
RewriteRule ^[/Žindex\.htm[l]]$ rewrite.html [R=301,L]

running thru it, step by step...
1) make sure that followsymlinks is on if it is allowed in that directory... if its not, it won't work...
2) ensure that rewriteengine is on
3) check if the request is for / OR
4) check if the request is for index.htm or index.html no matter what CaSe they type it in as
5) do the rewrite so that / and/or index.htm or index.html gets turned into rewrite.html with a 301 redirect code and the L denoting this is the last rule in the set

i've done this on the fly and not tested it on my test server... i normally do test them but can't access that portion of my server at the moment for some reason :(

i've found that there are times that one must check the {REQUEST_URI} to prevent recursion and looping of the server... i've had mine chew up all available memory and several gigs of swapspace on the drive before i was able to stop it and recover...

i've also been looking for jdMorgan to pop his head in here and show us something... however, it appears that he is away for a bit... hopefully he'll be back soon and can assist as well as correcting any errors that he may see...

oh yes... i do use a ¦ in the above but this board changes them to a solid bar so you'll have to edit that if you try to cut and paste the code...

[edit]fixed minor typos[/edit]


11:40 pm on Jul 26, 2003 (gmt 0)

10+ Year Member


actually, mod_rewrite can rewrite pretty much anything to anything... even going so far as to pull a section out of a URL and altering it... the tutorial on mod_rewrite on the apache web site has many example of this...

one should also note that there is a difference in how one writes their rules depending on if one is doing them in the .conf file or in the .htaccess file... and for what this is worth, neither of them have to be called by their default name... i've one site where .htaccess is not used at all but instead another name is used... its a simple matter of configuring in the configuration file ;)


4:09 pm on Jul 27, 2003 (gmt 0)

10+ Year Member

cool. Thanks for the advice, actually I ran into the recursion error myself! When you use the '/' if the rewrite points to a file in that same directory it can go into an infinite loop....

Featured Threads

Hot Threads This Week

Hot Threads This Month