Remove file extension (ie, .html) from URL

#79304
  • Resolved Sebastian Dietz
    Rank Math free

    Hello,
    I would like one url to show an html file but without the .html part
    For instance: https://mysite.com/link-a should show content of https://mysite.com/link-b.html but the url should show as https://mysite.com/link-b

    I know this can be done via .htaccess for removing .html part but our situation is a little more complex than that. We have multiple origin links that we cycle through multiple destination links and sometimes those destination links file names are exactly the same as the original links (ie, we redirect /link-a to /link-a.html). So if I add the .htaccess snippet for it, and link-a.html exists, but we are trying to redirect /link-a to /link-b.html, this does not work.

    In other words, what I would like to achieve is the functionality from Redirection’s plugin that allows you to “pass through” an url. I had achieved this behavior with that functionality in the past.

    I recently updated from 1.0.42.1 to 1.0.47 and I think this might be related, since we are mostly sure this was working before.

    Thank you in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Please add the following to you .htaccess file:

    
    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
    RewriteRule ^ /%1 [NC,L,R]
    
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^ %{REQUEST_URI}.html [NC,L]
    

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello Michael,
    thank you very much for your response! I will add it soon and test it again.
    Thank you again!
    Cheers

    Hello,

    Glad to hear that.

    Let us know how it goes.

    If you have any further question(s), please let us know. Thank you.

    Hello Micheal, how are you doing?
    Sadly, this didn’t work. I have put this at the very beginning of the .htaccess file.
    It is showing the content of /link-a.html, but in Redirection I have configured /link-a to redirect to /link-b (and therefore the content of /link-b.html should be shown). As link-a.html exists, this rule is applied before WordPress is reached and checked the existence of link-a => link-b.

    If I put it at the bottom, I get infinite redirects on some cases.

    The part of removing the .html works via .htaccess, but sadly not the redirection.
    Any thoughts? Maybe what I would like to achieve might not be possible without removing link-a.html temporarily?

    Thanks in advance!

    Hello,

    Could you please share the previous setup that you had with the redirection plugin so we can understand what exactly you were doing and if there is an option for doing that with Rank Math?

    If you just wish to redirect the .HTML versions of your website to the non .HTML versions, then it is pretty straight-forward and we can help you do that.

    But if you mean something, we need more information to help you better.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Remove file extension (ie, .html) from URL’ is closed to new replies.