I want to update all the pages on a website to use include for the footer and header. So I have to change a lot of .html pages to .php.
So i'm looking for a way to redirect all pages that end with .html to the same url but ending in .php.
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
If you want it to be done as a redirect instead of just a rewrite modify the [L]
to [L,R]
You could do a more simple approach and have all your html files be processed as php files by adding the following line to your .htaccess
AddHandler application/x-httpd-php .php .html
mod_rewrite to the rescue!
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php
In your apache httpd.conf file you can add
AddType application/x-httpd-php .html
to make .html files go through the php parser before they are served to the user. You can also add this directive to your .htaccess file. The second method may not work depending on how your host is setup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With