phphtml.htaccessmod-rewriteshtml

htaccess - rewrite .shtml and .html as . php


I'm pretty green with mod_rewrite. I've got the first line of this working like a champ, but the second part refuses to cooperate

RewriteRule ^(.*).html$ $1.php
RewriteRule ^(.*).shtml$ $1.php [R=301,L]

The .shtml part fails wonderfully and 404s - without my custom 404 page. Should this be combined in to one rule? Should I quit my job and let them hire a monkey to replace me? has anyone got a solution for this?

Thanks!


Solution

  • Assuming you are intending to redirect both .shtml and .html to .php...

    These should both be combined into one rule, and the problem looks to be that both match because the unescaped . before .html stands for "any character", which therefore also matches shtml.

    The pattern \.s?html will match the literal ., followed by an optional s, and ending with html.

    RewriteEngine On
    RewriteRule ^(.*)\.s?html$ $1.php [R=301,L]