3

I want to remove .html from all url's of site, I am working on x-cart and want to make it possible using .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>

I used this code but it doesn't work

Sandeep Nambiar
  • 1,656
  • 3
  • 22
  • 38
Karan Adhikari
  • 485
  • 1
  • 5
  • 16

3 Answers3

1

use like:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/?$ $1.html [NC,L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
Ishan Shah
  • 1,665
  • 2
  • 20
  • 42
  • @Starkeen — The OP has confirmed it does not work, which by itself is not a great reasoning. However the answer on its own failed to explain itself, it's not clear what any of the extra lines do, which could be dangerous implementing these kind of changes without knowing what they're going to do to the OP's system. – Alexander Wigmore Dec 16 '15 at 16:24
0

You can use:

# remove html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=301,L]

# add html but only if file exist with html and not without
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
Croises
  • 18,570
  • 4
  • 30
  • 47
0

you can use this to hide .html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]
Andrew
  • 2,810
  • 4
  • 18
  • 32