Will this .htaccess code work?

RewriteEngine  on

RewriteRule ^index.html$ index.php
RewriteRule ^realisations.html$ realisations.php
RewriteRule ^roofing-services-montreal/roofing.html$ roofing.php

I’m new to mod_rewrite, and it’s either my server doesn’t support the module or I’m doing something wrong.
Should the code above work properly if uploaded to www.website.com/.htaccess ?

Basically I’m trying to change specific .php pages to .html, and give some pages a fake sub-directory extension, will this work?
Thank you very much in advance.


If this is Apache 2.x, then yes it should work and indeed, a .htaccess file in the root of your website is correct as well.

If it is Apache 1.x --highly unlikely since I don’t think anyone uses that anymore-- it will not work, you’d need to change every ^ with ^/

Also, you need to escape dots in the filename, like this

RewriteEngine  on

RewriteRule ^index[COLOR="#FF0000"]\\[/COLOR].html$ index.php
RewriteRule ^realisations[COLOR="#FF0000"]\\[/COLOR].html$ realisations.php
RewriteRule ^roofing-services-montreal/roofing[COLOR="#FF0000"]\\[/COLOR].html$ roofing.php

Hi megashape,

Have you checked if your Apache server has mod_rewrite loaded? This needs to be loaded in the apache2,conf. Typically in Debian based distributions in root->etc->apache2->mods-enabled you need a rewrite.load like

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

. If you have this in there or in your main apache2.conf file and apache starts without errors then it should be loaded.

As you are using php you can also create a php page that has only:


or somewhere in one of the pages that you are trying to have a redirect to occur use:




Good thought but mod_rewrite code on a server where it’s not loaded and enabled would generate syntax errors which cause 500 errors to be sent, i.e., it’s enabled.