Skip to main content
Participant
October 26, 2018
Question

Inserting PHP code into an HTML document.

  • October 26, 2018
  • 3 replies
  • 874 views

So I have a website which is coded in HTML formatting. I need to insert some PHP code which is for the cookie consent stuff so I can be compliant with GDPR rules.

Do I need to convert the entire website into PHP from HTML format, or is there a way to insert PHP code into an HTML document without it spewing up loads of errors upon compiling?

Thanks

This topic has been closed for replies.

3 replies

Nancy OShea
Community Expert
Community Expert
October 26, 2018
Nancy O'Shea— Product User & Community Expert
Legend
October 26, 2018

If you do change all pages to a .php extension you may want to consider the impact and set up a redirect, this is assuming you are currently serving your pages with a .html extension (its more the norm these to serve pages without an extension). In this case you'll can use mod_rewrite to redirect all old .html files to their .php equivalent with something like this in htacess file:

RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L, R=301]

This keeps everything tidy and it guards against you losing any benefit of established pages that are generating traffic.

Paul-M - Community Expert
BenPleysier
Community Expert
Community Expert
October 26, 2018

How do I do this on an NGINX box?

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Legend
October 26, 2018

Something like this:

location ~ /(.*).html$

{ 

rewrite (.*).html$ /$1.php;
}


Paul-M - Community Expert
John Waller
Community Expert
Community Expert
October 26, 2018
  1. Does your webhosting account support PHP?
  2. If yes, is your webhosting account (the server) configured to parse HTML documents and look for and process PHP code? Ask your webhost.
  3. If not, you'll have to rename the page with a .php extension and update any links which point to it.
  4. No need to convert the entire site although for consistency it's often good practice, even for pages with no PHP code in them.