PDA

View Full Version : Redirect index.php to /


Dave Hawley
12-05-2006, 01:20/01:20AM
After a looooooong time of asking the question, searching and trying MANY different ways, I finally have a method that permantly redirects http://www.domain.com/forum/index.php to http://www.domain.com/forum/


RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]


Now, if I could only find out how to send default.htm to / Any ideas? I have tried all the usual suspects to no avail.

WebSavvy
12-05-2006, 01:24/01:24AM
In .htaccess add:
redirect 301 /default.htm http://www.domain.com/
Replace domain.com with your real domain.

HTH :)

Dave Hawley
12-05-2006, 01:44/01:44AM
Thanks, but that's not it. I have 3 main pages that end with /default.htm (eg http://www.domain.com/page/default.htm) and I need them redirected to http://www.domain.com/page/

redirect 301 page/default.htm http://www.domain.com/page/

Doesn't work.

WebSavvy
12-05-2006, 01:46/01:46AM
Dave, that's because you need to add the forward slash to it. :)

Try this:
redirect 301 /page/default.htm http://www.domain.com/page/
Anytime it's a folder being redirected from root, it needs a forward slash. Same with a page too.

Try it and let me know. OK?

Dave Hawley
12-05-2006, 01:54/01:54AM
My bad, that's was a typo. I have tried that way, and many others, but it causes an endless loop.

I have even tried modifying the .php one below to default & .htm etc but still no go.

RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

WebSavvy
12-05-2006, 01:58/01:58AM
OK, well ... right now I'm giving advice under the handicap of a migraine ... so ... I'll look at this tomorrow when my head is better. OK?

We have three other folks in here with lots of .htaccess/mod_rewrite/redirect knowledge & experience too, so maybe they'll also reply?

= 3

g1smd
ArmenT
chrishirst

delpino
12-05-2006, 06:52/06:52AM
I had the same problem and I am considering getting rid of index.php altogether and rename it to something like main.php or home.php. This plus the standard 301 redirect would avoid the loop.

ArmenT
12-05-2006, 23:41/11:41PM
RewriteRule ^/page/default.htm /page/ [R=301,L]

That ought to do it.

Dave Hawley
12-05-2006, 23:57/11:57PM
Thanks Armen. Unfortunately it didn't do anything :(

WebSavvy
13-05-2006, 00:25/12:25AM
Dave, maybe try this and see?

RewriteEngine On
RewriteBase /

RewriteRule ^page/default.htm$ /page/ [L]

WebSavvy
13-05-2006, 00:26/12:26AM
Are you on a UNIX server with Apache, btw? Or is it a Windows server?

Dave Hawley
13-05-2006, 00:54/12:54AM
Yeah sorry, I should have stated UNIX with Apache.

Thanks Sav but that one caused an "Internal Server Error".

As the one below does work for index.php to / Perhaps it can be modified to suit? I tried the obvious with no luck.

RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

WebSavvy
13-05-2006, 01:50/01:50AM
Yeah, I posted it wrong, Dave. I'm still under heavy headache. Should be gone by tomorrow. I'll have a look through some of my code snippets in my library and see if there's something there that might help.

Between all of us, I'm sure we'll come up with something that'll work.

Dave Hawley
13-05-2006, 03:47/03:47AM
Thanks Savvy. My 'trial and error' methods have all failed :(

g1smd
14-05-2006, 20:38/08:38PM
Have you tried this?

RewriteEngine on
# default.htm to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*default\.htm\ HTTP/
RewriteRule ^(.*)default.htm$ /$1 [R=301,L]

Sorry, not in a position to test it out right now...

Dave Hawley
14-05-2006, 20:56/08:56PM
Woooohoooo! g1smd, you are the man :cheers: