1

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!

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for your reply. Unfortunately I still get an internal error. Any suggestions? Edit: it does work on my local xampp server, but it does not on my host.
Can you post your complete .htaccess in your question so I can check and suggest.
I just tested this again and it worked well. You may have some conflicting rule which I can examine if you post your rules in question.
Even when the .htacces only consists of the following rules it the server still redirects the page to link, however when I run the script on xampp it does not give any errors. RewriteEngine On RewriteCond %{THE_REQUEST} /index\.(php|html?) [NC] RewriteRule ^(.*?)index\.(php|html?)$ /$1 [R=301,L]
I also tested it and it doesn't give any error. On the server where you get 500 can you check Apache error.log to see why 500 is coming.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.