How to rewrite .html url to. php file using .htaccess?

I have changed a website from .html extensions to .php; the file names are the same, and there are thousands of files. There is php code now which cannot be parsed with .html

Basically, since now all the files have a .php extension, I want to rewrite the url of all html files to become .php

In other words, if someone visits:

mysite.com/page.html

then they are taken to:

mysite.com/page.php

How can I do this in .htaccess?

RewriteCond $1.html !-f
RewriteCond $1.php -f
RewriteRule ^(.*)\.html$ $1.php

This reads: If the requested path ends in “.html”, and if the .html file does not exist but the .php file does, then rewrite the extension to .php.

3 Likes

There is an issue, when I do this, it displays the page but does not parse any PHP code.

halfway thru editing and boss called… finish in a sec :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.