0

Possible Duplicate:
Redirect *.htm to *.php
htaccess rewrite if redirected file exists

I set up a website a while ago and I had all the extensions as .html. I've learned a bit more about web development and would like to have everything as .php. The problem is that some of the pages have been bookmarked so I can't just change all the links and remove the .html files. I understand I could just add redirects on each page, but that would mean having two of each page on my site.

I'm wondering if there is a way using .htaccess to redirect any *.html to *.php if *.php exists.

Community
  • 1
  • 1
mowwwalker
  • 16,634
  • 25
  • 104
  • 157
  • @Michael, Alright, but how do I test if the php file exists? Not all of my pages with have their php version – mowwwalker Jan 17 '12 at 01:56
  • 1
    See also http://stackoverflow.com/questions/5437019/htaccess-rewrite-if-redirected-file-exists which deals more exactly with your same problem. – Michael Berkowski Jan 17 '12 at 01:59

1 Answers1

1
RedirectMatch 301 (.*)\.html$ $1.php

or In your apache httpd.conf file you can add

AddType application/x-httpd-php .html
Manigandan Arjunan
  • 2,260
  • 1
  • 25
  • 42
  • 1) `AddType` is inappropriate; `AddHandler` should be used. 2) processing all files with an extension of "html" as PHP scripts doesn't address Walkerneo's issue and is wasteful. – outis Mar 29 '12 at 00:51