Remove .html from URLs with a redirect

前端 未结 8 1573
一向
一向 2020-12-29 14:32

We have a website, unfortunately all the URLs have the .html suffix, its a Magento installation, Magento allows you to change this on the CMS, but again, unfort

相关标签:
8条回答
  • 2020-12-29 14:59

    This will rewrite the url like so http://example.com/page.html -> http://example.com/page

    # Remove .html from url
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html
    
    0 讨论(0)
  • 2020-12-29 15:02

    Here's the solution that worked for me.

        RewriteCond %{THE_REQUEST} \.html [NC]
        RewriteRule ^(.*)\.html$ /$1 [R=301,L]
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME}\.html -f
        RewriteRule ^(.*)$ $1.html [L]
    
    0 讨论(0)
提交回复
热议问题