Remove .html from URLs with a redirect

前端 未结 8 1642
一向
一向 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:37

    This is for URLs ending with .html /product/raspberrypi.html ---> /product/raspberrypi/ (/product/raspberrypi/index.php) the index.php is hidden. Took me awhile to figure this out. LOL...

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} \.html$
    RewriteRule ^(.*)\.html$ $1 [R=301,L]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    You have to use 'REQUEST_URI' and add it before index redirect rules since it could be overridden by the application. Its important to know that its URI not a filename or directory we are trying to redirect, since the file names all have index.php in the root folders(Wordpress).

提交回复
热议问题