Santhosh Fernando
Santhosh Fernando

Reputation: 137

Redirect index.php to root without affecting other urls

I need to redirect index.php to my root folder with out affecting other pages. I have tried this:

RewriteRule ^index\.php$ http://example.com/ [NC,R]

This one worked solved the problem in conditions such as

http://example.com/index.php but when I visit a URL such as

http://example.com/index.php?option=users, it displays as

http://example.com/?option=users which should not happen.

Upvotes: 0

Views: 89

Answers (1)

Ulrich Schmidt-Goertz
Ulrich Schmidt-Goertz

Reputation: 1116

According to the documentation, you need to add this line before the RewriteRule:

RewriteCond %{QUERY_STRING} ^$

This makes sure that the rule is only applied if the query string is empty.

Upvotes: 2

Related Questions