Genadinik
Genadinik

Reputation: 18639

Importing divs in a .html page

I think I made a mistake long ago of making .html extensions for my web pages in one site.

Now I want to do things like import divs, and make things modular, but I have a feeling it is not possible.

In PHP I could do something like

<?php
include("divs/footer.php");
?>

But how could I import a div in a page with a .html extension? Or does the .html extension not matter?

Thanks!

Upvotes: 0

Views: 118

Answers (2)

Paul
Paul

Reputation: 141829

You have a few choices. You could tell your server to execute .html files with the PHP interpreter, but that might be kind of confusing for someone in the future. I think it would be better to rename your pages to .php and update all links on your site. Then set up a redirect from the *.html to *.php with HTTP 301 so that any old bookmarks or links still work.

Another option you have is to use mod_rewrite to rewrite all your urls from /pagename.html to /index.php?page=pagename. Then you could have index.php just do something like:

<?php

if(strpos($_GET['page'], '../') !== false)
    die; // Do not allow traversing up the directory tree

require dirname(__FILE__).'/'.$_GET['page'];

?>

You may want to do more checking to make sure the file is valid, but that code will only require files below the web root so it should be safe to use.

Upvotes: 3

Kelly Cook
Kelly Cook

Reputation: 1261

The extension does not matter.

Upvotes: 4

Related Questions