how to redirect index.php to root using htaccess

# Switch rewrite engine on
RewriteEngine on

# Redirect non-www to www
RewriteCond %{HTTP_HOST} ^samprasanna.com$ [NC]
RewriteRule ^(.*)$ http://www.samprasanna.com/$1 [R=301,L]

# Do index.php to root redirect
RewriteCond %{THE_REQUEST} ^[A-Z]+ /([^/]+/)*index(.[a-z0-9]+)?[^ ]* HTTP/
RewriteRule ^(([^/]+/)*)index(.[a-z0-9]+)?$ http://www.samprasanna.com/$1? [R=301,L]

ErrorDocument 404 /404.php

Note: this code comfortable for only php and HTML sites
other CMS .htaccess code it’s totally different

Removing file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp

Leave a Reply