Removing .html extension from website - html

<center><button onclick="window.location.href='/shop.html'">SHOP</button></center>
I am trying to remove the .html tag from /shop.html. I have created a .htaccess file inside of my root folder. I included the follow inside;
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
I then removed the .html from /shop.html and had no luck with error 404.
Cheers, Ben.

RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
If the requested URL does not have an extension:
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
And it is not a directory:
RewriteCond %{REQUEST_FILENAME} !-d
And it is not a file:
RewriteCond %{REQUEST_FILENAME} !-f
And if by adding .html we find a file:
RewriteCond %{REQUEST_FILENAME}.html -f
Then add .html and serve that file:
RewriteRule (.*) $1.html [L]

Related

How do I remove the .html from the end of URL while using SiteGround

I had originally built my website in React before learning that my client is using SiteGround so I had to change everything over to a basic HTML format. I have my navbar using href = "fileName.html" to navigate the page. This leads the URL to become www."siteName".com/"fileName.html" once navigating off the homepage.
This is what I have so far in my .htaccess to remove the .html from the end:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
This does not seem to be working. Should I change my .htaccess file? Should I change the way my navbar navigates the pages?
With your shown samples/attempts, please try following .htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteBase /
###Rules for handling .html to without html uri in browser.
RewriteCond %{REQUEST_URI} \s/([^.]*)\.html\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.*)/?$ $1.html [L]
##Rule from OP's already existing .htaccess file.
RewriteRule ^index\.html$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>

RewriteRule .htaccess not working multiple

I have changed my .htaccess to make nice url.
What's wrong in this?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1 [NC,L]
RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([a-zA-Z0-9-/]+).html$ category.php?cat=$1 [NC,L]
RewriteRule ^category/([a-zA-Z0-9-/]+).html/$ category.php?cat=$1 [NC,L]
and I got from this
.htaccess rewriteRule conflict
I would to make like this
localhost/category/bla.html
localhost/seo/bla.html
and this is the url in database
bla.html
seo/bla-bla.html
just just move the bottom part up
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([a-zA-Z0-9-/]+).html$ category.php?cat=$1 [QSA,L]
RewriteRule ^category/([a-zA-Z0-9-/]+).html/$ category.php?cat=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/]+).html$ article.php?url=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9-/]+).html/$ article.php?url=$1 [L,QSA]

Changing url of html pages

I am trying to change the url of my html page to as below
example.com/intraday.html to example.com/intraday.
example.com/economic_calendar.html to example.com/economiccalendar
I am trying it using .htaccess file but it is not working
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.html
RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.html -f
RewriteRule ^ /%1.html [L]
Any suggestion.
https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)/?$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)([^/]+)/?$ $1_$2.html [L]

Remove .html off URL. .htaccess

I'm building a site in a Node.js container, and the .htaccess is not working. I just want to remove the .html off the url, but the following just downloads the pages as files. Sorry if this has been answered, just need help. Thanks!
What we currently have:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
To remove .html all you need to use is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
EDIT:
Some hosting services require a slightly different layout:
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Remove .html from url in apache2

I am trying to remove .html
so the site is www.example.com/login
login.html is located in /var/www/html/login.html
I created .htaccess in /var/www/html/.htaccess
And I put in:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
This doesn't seem to work. Can someone tell me what is wrong?
Try it this way.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.html [L]
Apparently you changed your question.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]