How to remove .html from URL?
Thanks for your replies. I have already solved my problem. Suppose I have my pages under http://www.yoursite.com/html, the following .htaccess rules apply.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
RewriteRule .* http://localhost/html/%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
RewriteRule .* %1.html [L]
</IfModule>
how to remove the url extension
try create .htaccess
file on your root folder then paste this
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
you can read more about this here https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/
EDIT
Since you are using Vercel.com, as per their documentation there's a file config named vercel.json
you can add this
{
"cleanUrls": true
}
the docs said,
When set to true, all HTML files and Serverless Functions will have their extension removed. When visiting a path that ends with the extension, a 308 response will redirect the client to the extensionless path.
for more information pls read their docs here https://vercel.com/docs/configuration#project/clean-urls
How to remove .html from URL and redirect when the html will be accessed directly
In your .htaccess file try adding:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
should remove .html
and add a trailing /
source
Netlify remove .html on url slug
You need to untick Disable asset optimization under Settings -> Build & deploy
See link for example taken from.
If that does work try the solution from the community.
Truly hope that helps.
If I remove .html from URL will old links still work?
Answer is YES, they will work, if you edit .htaccess to hide the extension.
You can check more about how it works here.
Related Topics
Error Error: Formcontrolname Must Be Used With a Parent Formgroup Directive
How to Remove Indentation from an Unordered List Item
Navbar(Menu) Is Getting Overlapped by Body Element
Item Moving Around When Window Resized
Angular 5, Html, Boolean on Checkbox Is Checked
How to Disable Hover Effect for Active Link
How to Disable an Input Dynamically With Angular 7
How to Align Two Submit Button on Same Line
How to Remove the White-Space Created by an Image
How to Limit the Maximum Files Chosen When Using Multiple File Input
How to Display Image Encoded in Base64 Format in Angular 6
How to Make CSS Grid Items Take Up Remaining Space
How to Declare a Variable in a Template in Angular
Woocommerce Change Product Image on Hover With CSS
Angular (Typescript): How to Set Option of Selected to 'Selected' If Two-Way Binded
Maxlength Ignored for Input Type="Number" in Chrome
How to Remove Hover Effect from Bootstrap Button
Element Will Not Stay Centered, Especially When Re-Sizing Screen