I wanted my website to show as: www.example.com
.
Instead of: www.example.com/index.html
.
I tried to change the code as per below to remove the .html
, and it works.
But how I can hide the /index
on the main page on the URL?
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^$ http://example.com/index.html [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Add this to your .htaccess
file in your server:
RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]
Tested on an Apache 2.0 server.
For more, see my answer on infinity free discussion.