Answer the question
In order to leave comments, you need to log in
How to remove .html at the end of the address of each web page of the site, without using php?
I have read that it is possible to remove .html using .htaccess file, but all the code I have seen for removing .html is written in php.
And since I use free hosting and it has a ban on using php, I can't remove .html.
Is it possible to somehow remove the file extension at the end of the address without using php?
Java script like...
Answer the question
In order to leave comments, you need to log in
RewriteEngine On
RewriteCond %{REQUEST_URI} ! \.html$
RewriteCond %{REQUEST_URI} ! /$
RewriteRule ^(.*)$ $1.html
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Explanation:
#Turn on the conversion mechanism
RewriteEngine On
#Set the condition "the file path is specified in url?"
RewriteCond %{REQUEST_FILENAME} !-f #If
yes, then just remove html
RewriteRule ^([^\.]+)$ $1.html [NC,L]
PS Now we specify the path in the code like this: <a href="example">Example</a>
And of course, instead of $1.html, you can write $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L,QSA]
RewriteCond %{THE_REQUEST} ([^\s]* )\.php(\?[^\s]*)?
RewriteRule (.*) %1 [R=301,L]
for those who need to remove the php extension from the url (address bar). code tested and working
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question