0

We have some wrong URLs in our store ending with .html. If the user opens such a URL, then the .html should get removed, otherwise the site cant get found.

So I added this rule to my .htaccess file in pub/.htaccess, i also tried the normal .htaccess in the magento root.

<IfModule mod_rewrite.c>

...

############################################
## Remove .html from end of URL

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)\.html$ /$1 [L,R=302]

</IfModule>

But if I enter a URL with .html at the end, then it is still not getting removed.

I want to make it work by using the .htaccess, otherwise I will have to create plenty of URL rewrites by hand.

2
  • Why you not using Magento 2 default configuration for this..? Commented Dec 1, 2020 at 16:03
  • What do you mean exactly?
    – Black
    Commented Dec 2, 2020 at 8:23

1 Answer 1

0

Hi I understand actually you want to redirect .html page to without.html page

You can add following code in .htaccess : for example :

Redirect /specific-page.html /specific-page 
2
  • Yes, but I dont want to redirect a single page, I want to redirect ALL URLs.
    – Black
    Commented Dec 2, 2020 at 8:24
  • Try this : RedirectMatch (.*)\.html$ http:// example.com$1 Commented Dec 3, 2020 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.