: Removing .html and index.html from URL I'm having some problems trying to Remove the .html extension from URLs Removing 'index.html' from an URL 1) To remove the extension I have tried using
I'm having some problems trying to
Remove the .html extension from URLs
Removing 'index.html' from an URL
1) To remove the extension I have tried using this in my htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ .html
However when I click links in my HTML such as <a href="abcde.html"></a> it doesn't remove the .html from the URL and I am left with website.com/abcde.html
2) I tried using this to remove the index.html
RewriteCond %{THE_REQUEST} /index.(php|html) HTTP [NC]
RewriteRule (.*)index.(php|html)$ / [R=301,L]
But when I load an index.html file on my server, my URL looks something like this
website.com/folder//
I am left with an extra / at the end.
Can anyone help me out?
More posts by @Barnes591
2 Comments
Sorted by latest first Latest Oldest Best
Building on the answer Anagio provided, let's cover all your requirements:
Transparently serve .html files on requests like /path/to/file if /path/to/file.html exists
Deny direct requests against /path/to/file.html
Serve /index.html on requests against /
Directory configuration:
Options +FollowSymLinks -MultiViews
DirectoryIndex index.html
RewriteEngine On
#
# Rewrite valid requests on .html files
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA]
#
# Return 404 on direct requests against .html files
RewriteCond %{REQUEST_URI} .html$
RewriteCond %{QUERY_STRING} !rw=1 [NC]
RewriteRule ^ - [R=404]
This is from stackoverflow
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.