I have a website in html, css and javascript (without libraries or framework) and I need to embed an external footer and header to make it easier to maintain. I found the following code that would solve it, but they clarify that, if it doesn't work, the .htaccess must be configured and I have no idea what it refers to...
<!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>
For your code to work you must consider the following:
the file extension
The files you want to execute language logic like PHP ; then they must have extension
.php
; what I mean is:instead of having this:
archivo.html
you should have this:
archivo.php
The next thing is that you have to run these files from an apache or ngnix server; if you are starting and working on Windows; you have the first in packages like XAMPP that already include you: PHP, MySQL, Apache
Under the assumed scenario above, you should save your project in the following path
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 typing xampp panel
You are going to run Apache and later in your browser you will do the following
Where projectFolderName is the name of the folder where you stored your project
Note
You must consider that Apache by default will look for a file with the name
index.php
to load its content in the browser, otherwise it will show you the list of files that you have stored, consider naming one as I sayAt least for what you mention you don't need to configure anything in the
.htaccess
If your question goes more to
You must do the following:
In the root of the project you create the file if it does not exist
.htaccess
and you must add the following line:It means that the extensions
.html
or.htm
are PHP applicationsI leave the documentation about AddType