Josh Undefined
Josh Undefined

Reputation: 1536

.htaccess rewrite subfolders to remove /index

I have some htaccess rules which rewrite friendly URLs. Everything is working apart from one thing.

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]

This is a site with language subfolders, e.g.:

/fr/about.html

/en/about.html

With the above htaccess rules these urls come out like:

/fr/about

/en/about

However this also means my index pages URLs look like:

/fr/index

/en/index

What I would like, is for /index the URL looks like

/fr

/en

Which would mean they respect the trailing slash part of my above htaccess but remove index from the URL.

Any help much appreciated!

Upvotes: 0

Views: 54

Answers (1)

Croises
Croises

Reputation: 18671

Try to add (before RewriteCond %{THE_REQUEST} ^...):

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*?)/index(\.html)?[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

Upvotes: 0

Related Questions