Question

I am running into a problem concerning the mod_rewrite.

RewriteCond %{THE_REQUEST} /index\.[php|html] [NC]
RewriteRule (.*)index\.[php|html]$ /$1 [R=301,L]

The idea is to get both domain.com/index.php and domain.com/index.html redirected to domain.com. My attempts do not seem to work. The above code is one of my attempts.

It would be great if you could help me out!

Was it helpful?

Solution

Your regex is incorrect You need to use ( ) instead of [ ].

Use this rule:

RewriteCond %{THE_REQUEST} /index\.(php|html?) [NC]
RewriteRule ^(.*?)index\.(php|html?)$ /$1 [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top