homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod rewrite question & index files
scorpion




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

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.

E.g

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

Surfing to this directory
"http://www.testserver.com/rewritedir/"

returns:

Forbidden
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?

 

wkitty42




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

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

my.domain.com/somedir/

and

my.domain.com/somedir/index.html

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)...

tschild




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

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

Does adding the following line help?

RewriteRule ^$ rewrite\.html [L]

wkitty42




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

scorpion,

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]

wkitty42




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

tschild,

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 ;)

scorpion




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

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....

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved