how to set up htaccess to be able to embed .php in HTML files

2

I have a web in html, css and javascript (without libraries or framework) and I need to embed footer and external header to make it easier to maintain. I found the following code that would solve it, but they clarify that, if it does not work, the .htaccess should be configured and I have no idea what it means ...

<!DOCTYPE>
<html>

<head>
  <title>Titulo de pagina</title>
</head>

<body>
  <?php
include "header.html";
?>
    // Todo el contenido de la pagina... etc...
    <?php
include "footer.html";
?>
</body>

</html>
    
asked by Fernanda 13.12.2018 в 12:18
source

2 answers

2

If your question goes more to

  

How to add PHP code to pages with extensions .html or .htm

You should do the following:

In the root of the project you create the file if there is no .htaccess and you must add the following line:

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

It means that the .html or .htm extensions are PHP applications

I leave the documentation on AddType

    
answered by 13.12.2018 / 14:43
source
2

To make your code work, you should consider the following:

the file extension

The files you want to run are language logic such as PHP ; then they must have .php extension; what I mean is:

instead of having this: archivo.html

You must have this: archivo.php

The next thing is that you must run these files from an apache or ngnix server; if you are starting and working in Windows; the first is in packages like XAMPP that already include you: PHP, MySQL, Apache

Under the previous scenario, you should save your project in the following route

xampp/htdocs

And inside HTDOCS you are going to paste your folder with your project; Once the above is done, you will search to open the xampp panel from Start in Windows and by typing xampp panel

You will give Apache run and later in your browser do the following

localhost/nombreCarpetaProyecto

Where ProjectFolderName is the name of the folder where you stored your project

Note

You should consider that Apache by default will search for a file with the name index.php to load its contents in the browser, otherwise it will show you the list of files that you have stored, consider naming one as I tell you

At least for what you mention, you do not need to configure anything in .htaccess

    
answered by 13.12.2018 в 14:40