How to remove .html from URL?

前端 未结 12 1763
轻奢々
轻奢々 2020-11-22 03:02

How to remove .html from the URL of a static page?

Also, I need to redirect any url with .html to the one without it. (i.e. www.exam

12条回答
  •  梦谈多话
    2020-11-22 03:24

    This should work for you:

    #example.com/page will display the contents of example.com/page.html
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L,QSA]
    
    #301 from example.com/page.html to example.com/page
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
    RewriteRule ^(.*)\.html$ /$1 [R=301,L]
    

提交回复
热议问题