Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Index Problem

www.example.com/index.htm works but www.example.com/ does not

         

diggersf

12:34 am on Aug 31, 2005 (gmt 0)

10+ Year Member



I'm trying to do this rewrite. www.example.com should rewrite to www.example.com/anydir/ and load up the DirectoryIndex (index.htm). It works fine if I specifically type www.example.com/index.htm, but I get a 404 if I leave out the index.htm. Here is my .htaccess code.

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{REQUEST_URI}!^/anydir/
RewriteRule ^(.*)$ /anydir/$1

Thanks for any help.

jdMorgan

1:30 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you defined the index page in the new subdirectory using the DirectoryIndex directive?

Jim

jd01

1:33 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DirectoryIndex (index.htm)

If this is the syntax in the file, it is probably the issue:

DirectoryIndex index.htm

If not the you may be getting into trouble with the base defined as / and the path defined with a preceding /

I think this would be more solid:

Options +FollowSymlinks

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/anydir/
RewriteRule ^(.*)$ /anydir/$1 [L]

Hope this helps.

Justin

Hi jdMorgan =)

diggersf

1:59 am on Aug 31, 2005 (gmt 0)

10+ Year Member



Thanks for the fast answers! Still no luck. I verified that the DirectoryIndex was set in the directories corrctly and I tried the new code you suggested. All the images and style sheets load if I type index.htm in directly but I just dosn't want to load the directory index on its own. Any more advice? I've spent the past few days browseing the board and you guys seem to be the masters. Thanks.

jd01

5:59 pm on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Personally, I would just force it to display the right page and not mess with it any more =)

RewriteEngine on

# Rewrite index.htm OR index.html OR / to /anydir/index.htm
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(index\.html?)?$ /anydir/index.htm [L]

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{REQUEST_URI}!^/anydir/
RewriteRule ^(.*)$ /anydir/$1 [L]

Hope this helps.

Justin

Oh, and jdMorgan is the master - I'm just a rookie.

diggersf

7:06 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



Dont be so modest! Thanks! I never though of it that way. It seems as though the code I had would work but it's a mystery to me.

Of course, I'm still curious as too why the work around is neccessary. Not important but anyone have any ideas? Thanks again.