I can open my site like this:
www.mysite.com
or like this:
www.mysite.com/index.php
I want to create a htaccess rule that redirects www.mysite.com/index.php to www.mysite.com. But all my attempts have other side effects. I’ve tried:
Redirect index.php home.php
RewriteRule ^index.php?$ home.php [NC,L]
RewriteRule ^index.php/?$ redirect_to_home.php [NC,L]
But all of these mess up the original index.php call. So it does redirect but then the normal mysite.com link doesnt work anymore.
Any ideas?
2
Answers
Use this redirect rule to remove
/index.php
from any path:Could you please try following.
Explanation:
RewriteEngine On
to make the rules work.RewriteCond
toREQUEST_FILENAME
which checks if mentioned file in browser is present.THE_REQUEST
which has complete details of request(including URL and GET/POST method) if it has index.php in it.REQUEST_URI
is havingindex.php
in requested url, where saving everything before it to temp buffer memory to retrive its value later(basically its domain name).RewriteRule
to redirect complete URL with index.php to till domain name only as per requirement(R=301 is for permanent redirection on browser side).