Search code examples
.htaccessmod-rewriteurl-rewriting

Simple Rewrite Rule issue


I have a bit of hard time trying to understand what is wrong with the 3rd line of this rewrite rule :

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
RewriteRule ^fr/lecon-de-kite\.html$ kite-lessons.php?lang=fr [L]
RewriteRule ^fr$ index.php?lang=fr [L]
RewriteRule ^it$ index.php?lang=it [L]

when I try to reach http://localhost/kitemeup/fr/lecon-de-kite.html I get an Not Found error


Solution

  • Have it like this in your site root .htaccess:

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^fr/lecon-de-kite\.html$ kite-lessons.php?lang=fr [L]
    RewriteRule ^(it|fr)/?$ index.php?lang=$1 [L,QSA]
    
    RewriteRule ^(.+)\.html$ $1.php [L,NC]
    

    Just understand that ordering of rules is important as mod_rewrite processes them from top to bottom. Your html -> php rule was taking precedence and converting all .html URIs to .php making your 2nd rule ineffective.