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!

有帮助吗?

解决方案

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]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top