You are not logged in.

#1 2007-08-26 11:42:49

Galdona
Member
Registered: 2006-03-15
Posts: 196

removing index.<whatever> from site url in .htaccess using mod_rewrite

I'd like to remove the "index.cgi", "index.php", or "index.html" filenames from all my site's urls, as long as there isn't an actual file with that filename. I would also like to keep the query string intact. Thus:

http://example.com/section1/index.php?name=whatever

should become

http://example.com/section1/?name=whatever

Below what I have come up with so far, and I'm sure it must be grossly mistaken. It doesn't seem to have an effect. I'm finding it very difficult to grasp mod_rewrite+regexps, so please help with this little thing?

# .htaccess file 
RewriteEngine On 
RewriteCond %{REQUEST_URI} !-f 
RewriteCond %{REQUEST_URI} !-d 
RewriteCond %{REQUEST_URI} /index\.(php|cgi|html) 
RewriteRule ^.*$ / [R=301,L]

Offline

#2 2007-08-26 12:53:36

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: removing index.<whatever> from site url in .htaccess using mod_rewrite

What I mean is that if the user types in "example.com/index.php?foo=bar" in his address bar, he will be redirected to "example.com/?foo=bar".

Offline

#3 2007-08-28 02:30:33

rab
Member
Registered: 2006-06-15
Posts: 185

Re: removing index.<whatever> from site url in .htaccess using mod_rewrite

i forget parts of mod rewrite but something like this...

RewriteEngine On 
# Anything index.php?cat=funtime goes to /?cat=funtime
RewriteCond %{REQUEST_URI} index\.(php|html|cgi)\?.*$ NC
RewriteRule index\.(php|html|cgi)\?(.*)$ /$2 R[=301]

# Now our url is pretty
RewriteCond %{REQUEST_URI} ^\?
RewriteRule ^(.*)$ index.php$1 [L]

something like that


rawr

Offline

Board footer

Powered by FluxBB