Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect all .html extensions to .php

Tags:

.htaccess

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.

like image 604
Max Avatar asked May 13 '11 09:05

Max


4 Answers

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]

like image 188
James C Avatar answered Nov 03 '22 19:11

James C


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
like image 26
Jordonias Avatar answered Nov 03 '22 21:11

Jordonias


mod_rewrite to the rescue!

RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php
like image 6
Pål Brattberg Avatar answered Nov 03 '22 19:11

Pål Brattberg


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.

like image 1
wewals Avatar answered Nov 03 '22 21:11

wewals