homepage Welcome to WebmasterWorld Guest from 107.21.163.227
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

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

Apache Web Server Forum

    
mod_rewrite help - removing filename
how do i remove a filename
florida_guy




msg:1503082
 4:30 pm on Jan 16, 2003 (gmt 0)

Hi,

I'm trying to remove index.html from any request.

So, if the request is for '/index.html' needs to be changed to just '/'

I've tried:
<code>
RewriteRule ^index\.html?$ / [R=301,L]
</code>

I'm kinda new to mod_rewtite and I keep crashing the server. Thanks for any input...

Doug

[edited by: florida_guy at 4:34 pm (utc) on Jan. 16, 2003]

 

florida_guy




msg:1503083
 4:33 pm on Jan 16, 2003 (gmt 0)

Could this be done as a redirect in the htaccess? I'm confused...

DaveAtIFG




msg:1503084
 5:09 pm on Jan 16, 2003 (gmt 0)

This Intro to Redirects [webmasterworld.com] will help get you started. Welcome to WebmasterWorld! :)

jdMorgan




msg:1503085
 5:17 pm on Jan 16, 2003 (gmt 0)

florida_guy,

Welcome to WebmasterWorld [webmasterworld.com]!

There's an interaction here between mod_rewrite and mod_dir. See the online docs for mod_dir at http://httpd.apache.org/ [httpd.apache.org].

You need an intermediate step - rename your index.html to index.htm (for example).
mod_rewrite index.html to "/" with a 301 redirect.
let mod_dir rewrite the request for "/" to index.htm silently.

The above is just a quick outline, but it will allow you to get rid of "index.html" in the URL shown by search engines for your site home page. mod_dir must be set up correctly for this to work.

HTH,
Jim

<edited>typo</edit>

[edited by: jdMorgan at 5:24 pm (utc) on Jan. 16, 2003]

andreasfriedrich




msg:1503086
 5:21 pm on Jan 16, 2003 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com] florida_guy.

Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.

The easiest way to remove index.html from most requests would be not to use links that end with /index.html on any of your pages. Then the only requests that will ever use the index.html are the ones manually entered by people who just hope that that will be the default filename.

To catch those cases use RewriteRule (.*)/index\.html?$ $1/ [R,L] in you top level .htaccess file or better yet httpd.conf (if you have access).

Your rule would always rewrite the URI to the domain root.

DaveAtIFG wrote an excellent tutorial on mod_alias and mod_rewrite which might be helpful for future reference: An Introduction to Redirecting URLs on an Apache Server [webmasterworld.com]

Andreas

<edit>Dave and Jim were faster ;). Go with their advice. Mine is basically the same.</edit>

<edit2>typo</edit2>

[edited by: andreasfriedrich at 6:35 pm (utc) on Jan. 16, 2003]

florida_guy




msg:1503087
 6:02 pm on Jan 16, 2003 (gmt 0)

Thanks everyone for your input.

It's working properly now. I was close to getting it. Thanks andreasfriedrich for the code.

I had to make sure I put:
RewriteRule (.*)/index\.html?$ $1/ [R,L]

AFTER

RewriteBase /
RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1]
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html

Which allows a .php file to be called with .html

When I put it after, I got funky results...

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved