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!

anubhava
  • 761,203
  • 64
  • 569
  • 643
Fabian
  • 107
  • 2
  • 2
  • 9

1 Answers1

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 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. – Fabian Jan 31 '14 at 17:26
  • Can you post your complete .htaccess in your question so I can check and suggest. – anubhava Jan 31 '14 at 17:28
  • 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. – anubhava Jan 31 '14 at 17:33
  • Even when the .htacces only consists of the following rules it the server still redirects the page to [link](http://www.bhosted.nl/error/error500.html), 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] – Fabian Jan 31 '14 at 17:37
  • 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. – anubhava Jan 31 '14 at 17:40
  • I am moving to another host soon, so I will see how it goes. It works on localhost, so it should work on a real server as well. But I could still contact the help desk of my current provider for research purposes if you like. – Fabian Jan 31 '14 at 18:42
  • Yes it should definitely work and I have verified it and you also have verified it on localhost. 500 could be caused for ex. if mod_rewrite isn't enabled. If you're satisfied with the answer you can mark it as accepted. – anubhava Jan 31 '14 at 19:06