How to Remove .Html from Url

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



Leave a reply



Submit