Forum Discussion

demmo_251289's avatar
demmo_251289
Icon for Nimbostratus rankNimbostratus
Dec 22, 2016

adding 301 redirect to page extension swap

Hello, I've got below snippet to replace .html to .htm. It works fine but i'd like to add a 301 redirect. Could you please help me with that ?

Thank you

if { [HTTP::path] ends_with ".html" } {
    HTTP::uri [string map -nocase {".html" ".htm"} [HTTP::path]]
}

1 Reply

  • Try:

    if { [HTTP::path] ends_with ".html" } {
        HTTP::uri [string map -nocase {".html" ".htm"} [HTTP::path]]
        HTTP::respond 301 Location "http://[HTTP::host][HTTP::uri]"
    }