Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using .htaccess to make all .html pages to run as .php files?

I need to run all of my .html files as .php files and I don't have time to change all of the links before our presentation tomorrow. Is there any way to "hack" this with my Apache server?

like image 638
Michael Novello Avatar asked Jan 14 '11 01:01

Michael Novello


People also ask

Can you include PHP in HTML file?

As you can see, you can use any HTML you want without doing anything special or extra in your PHP file, as long as it's outside and separate from the PHP tags. In other words, if you want to insert PHP code into an HTML file, just write the PHP anywhere you want (so long as they're inside the PHP tags).

What is .htaccess file in PHP?

htaccess is a configuration file for use on web servers running on the web apache server software. when a . htaccess file is placed in a directory which in turn loaded via the Apache web server, then the . htaccess file detected and executed by the Apache server software.

How a .PHP file is different from a .HTML file?

PHP is a scripting language | HTML is a markup language. PHP code is executed on the server | HTML code is parsed by the client browser. PHP creates dynamic web pages | HTML creates static web pages. PHP can access a database | Database cannot be accessed using HTML.


2 Answers

Create a .htaccess file at the root of your website and add this line:

[Apache2 @ Ubuntu/Debian: use this directive]

AddType application/x-httpd-php .html .htm 

Or, from comment below:

AddType application/x-httpd-php5 .html .htm 

If your are running PHP as CGI (probably not the case), you should write instead:

AddHandler application/x-httpd-php .html .htm  
like image 112
Marc-François Avatar answered Sep 16 '22 15:09

Marc-François


In My Godaddy Server the following code worked

Options +ExecCGI AddType application/x-httpd-php .php .html AddHandler x-httpd-php5 .php .html 
like image 21
tony Avatar answered Sep 17 '22 15:09

tony