views:

49

answers:

2

Hello.

I was writing a PHP (Kohana) app and I saw that the controller index pages could be seen with & without /index.

http://plugb.com/ & http://plugb.com/index

In order to avoid duplicated content, I did this:

$clean_url = str_replace('index','',$this->request->uri);

if($clean_url !== $this->request->uri)
{
 $this->request->redirect($clean_url);
}

I would like to know how to do the same, but with .htaccess.

Thank you in advance.

+2  A: 

Not tested, but I suspect this should work:

RewriteRule ^(.*)/index$ $1 [L,R=301]
Victor Nicollet
+2  A: 

Try this rule:

RewriteRule ^index($|/(.*))$ /$2 [L,R=301]

This rule will remove any leading /index from the URL path.

Gumbo