rewriting default index file

New to mod_rewrite? This is a good place to start.

rewriting default index file

Postby quazilitic » Thu Sep 04, 2003 8:41 pm

the rewrite rule is not applied to 'index.html' when the URL points just to the directory. i need it to. this should be the expected behavior.

it worked on my apache 1.3 install, but not on apache 2.0
quazilitic
 
Posts: 4
Joined: Thu Sep 04, 2003 8:34 pm

Postby aaroncimolini » Fri Sep 05, 2003 1:17 am

so what you are saying is when you go to:

http://example.com/index.html

your Rewrite rule is applied. But when you go to:

http://example.com/

your Rewrite rule is not applied. If thats the case then that is the default behaviour and how it works with my apache 1.3 server. With mod_rewrite you have to specify the exact pattern to match, if the text in the request string does not exactly match the pattern the the rule will not be applied.

I suggest adding a RewriteRule for the case where the user only requests the root with a url like this:

http://example .com/

Try this to match the root of your web server

RewriteRule ^/$ /index.html

if you want this rule to rewrite all index files no matter what directory they are in try this

RewriteRule ^/(.*)/$ /$1/index.html

Hope that helps you out :)

Aaron
User avatar
aaroncimolini
 
Posts: 5
Joined: Thu Sep 04, 2003 12:14 am

Postby quazilitic » Fri Sep 05, 2003 10:05 am

this is my problem. and i got the desired behavior on my redhat 7.2 box.

your solution doesn't account for all the different possible default documents that my be in a given directory. for example: http://example.com/scrapbook might have a index.php file. if i implement your rewrite rule, a request to that directory would try to send http://example.com/scrapbook/index.html which doesn't exist.

you see, mod_write must play nicely with default documents and allow them to be backreferenced in the RewiteRule. for some reason it worked on an older setup.

sys-admin... *sigh*
_
scott
quazilitic
 
Posts: 4
Joined: Thu Sep 04, 2003 8:34 pm

Postby aaroncimolini » Sat Sep 06, 2003 12:19 am

What was the original Rewrite Rule that you were trying to apply to the index.html files? were you trying to pass some variables to a php file?
User avatar
aaroncimolini
 
Posts: 5
Joined: Thu Sep 04, 2003 12:14 am

Postby quazilitic » Sat Sep 06, 2003 9:43 am

RewriteRule ^(.*\.html.*)$ /template.php?r=$1

this would some how rewrite a request to "http://example.com/somedirectory/" -> "http://example.com/template.php?r=/somedirectory/index.html" if ther was a index.html, of course.
_
s
quazilitic
 
Posts: 4
Joined: Thu Sep 04, 2003 8:34 pm

Postby Guest » Mon Sep 08, 2003 1:15 pm

nice, how does that rule work for you? I thought you may have some troubles with matching the .html part. What if a user just requests:

http://example.com/somedir/

the .html.* part probably wont match and then the rule may fail :(

let me know
Guest
 

Postby quazilitic » Tue Sep 09, 2003 12:32 pm

yes. that's the problem. am i not being clear here?

the above posted rule was in response to the question of what the original working rule was on a redhat 7.2 box (apache 1.3).

IT NO LONGER WORKS ON MY REDHAT 9.0 BOX (apache 2.0)

something has changed in configuration and/or mod_rewrite version that no longer matches an implied default document. it need's to. this should be a common problem.

_
scott
quazilitic
 
Posts: 4
Joined: Thu Sep 04, 2003 8:34 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 27 guests

cron