sbaaaang sbaaaang - 2 months ago 18
Apache Configuration Question

HTACCESS remove ext html from url

I have urls like these:

site.com/user.html?id=2

site.com/user.html


all i need is to return the same page removing ".html" so:

site.com/user


in case of somenthing after ".html" i need to add back slash

site.com/user/?id=2


is there anyway to do this in htaccess?

i'm only using js and html pages (no server side languages)

Answer

Copy, paste and edit from Apache .htacces Rewrite Rule to Remove .php File Extensions

Options +FollowSymlinks -MultiViews
RewriteEngine on

# to make `/path/index.html` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.html [NC]
RewriteRule . %1 [NE,R=301,L]

RewriteCond %{THE_REQUEST} ^GET\s.+\.html [NC]
RewriteRule ^(.+)\.html$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_URI} !\.html$ [NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule . %{REQUEST_URI}.html [L]
Comments