Forum Moderators: phranque

Message Too Old, No Replies

strip index.html

How do i strip off the index.html from the requset?

         

basilcrow

7:35 pm on Sep 1, 2003 (gmt 0)



I have a website in which many people link to files such as /info/index.html . I don't like this, as I may change the default directoryindex in the future, or switch to a different server-side technology such as PHP or something. What I'm trying to come up with is a mod_rewrite rule that will take a browser request like: /info/index.html and *visibly, permanently* redirect it to /info/ ... so i tried the following mod_rewrite rule:

RewriteEngine On
RewriteCond %{REQUEST_URI} index.html$
RewriteRule (.*)index.html $1 [R=302,L]

But it goes into an infinite loop of some sort and doesn't work. Any ideas?

Thanks MUCH appreciated in advance.

Basil

Duckula

8:13 pm on Sep 1, 2003 (gmt 0)

10+ Year Member



You don't need to do this. If you change later to .php, rewrite then, not now. "Premature optimization is the root of al evil", yadda yadda.

jdMorgan

8:17 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Basil,

Welcome to WebmasterWorld [webmasterworld.com]!

Yes, it will go into an infinite loop, unless you change the name of the actual index file.

If you want to sort this out, first change all internal links on your site to refer to your index page(s) as "../", "/", or "http://yourdomain.com/path_to_directory/". Having done that, you can change the server's default index page using "DirectoryIndex" in Apache. Name your index page something other than "index.html" or "index.htm". Then you can redirect all requests for "index.html" to your actual index file, but leave requests for "/" as-is.

If you later opt to change to php, cfm, asp, or whatever, all you'll need to do is change the DirectoryIndex directive, and you'll be done. This is actually the main reason to prefer linking to your index pages(s) using "/" instead of specifying a filename and filetype (and thereby, the technology).

Jim

basilcrow

9:02 pm on Sep 1, 2003 (gmt 0)



If you later opt to change to php, cfm, asp, or whatever, all you'll need to do is change the DirectoryIndex directive, and you'll be done. This is actually the main reason to prefer linking to your index pages(s) using "/" instead of specifying a filename and filetype (and thereby, the technology).

Change noted. But other people still link to my pages with the "index.html" included. So how can I rewrite the URL to eliminate that "index.html" fragment?

jdMorgan

9:43 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Then you can redirect all requests for "index.html" to your actual index file, but leave requests for "/" as-is.

As noted, you can't... until you rename the actual file and change DirectoryIndex.

Jim