Reputation: 369
I built a website some time ago for a company and its pages are primarily in html with a few php pages to support some dynamic content.
The company now requires dynamic content on their index.html page and although I was under the impression I could just open up some standard php tags, add in my lines of php and away you go, it appears that's not the case and my php will not run.
Can anyone explain what is required in order for my php code to run within a .html page?
Thanks, Jonny
Upvotes: 1
Views: 320
Reputation: 1972
put redirect code in index.html redirect to a file with .php extension and put all the index.html material there and put whatever addtional code you want to put in it.
so when someone reaches index.html, they'll be taken to suppose home.php where the index.html content will stay and your dynamic code.
this is the simplest solution if u cant change the index.html to index.php.
Upvotes: 0
Reputation: 7839
The easiest way is to name them .php but if you need to keep them as .html you could use Mod Rewrite on your server allow the .html links to be perfectly valid.
Update: As your on a Windows Server you could use this package http://www.seoconsultants.com/windows/isapi/ to allow rewriting of the URLs. It works much the same as Mod_Rewrite from what I can gather.
Upvotes: 0
Reputation: 20475
You have two options to get where you need to go:
For process sake, and ease of support I would do number one, here are the solutions for both:
Mod-rewrite (.htaccess file), you will need equivalent .php files for all your .html files.
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
Add this to your Apache config file:
AddHandler application/x-httpd-php .php .html .htm
Upvotes: 1
Reputation: 3201
If the server has a PHP module installed, you could configure the web server to process .html files through that PHP module. (With AddHandler
for Apache for example)
Otherwise, rename the files to .php and have some fancy URL rewriting that allows them to be called via .html.
Upvotes: 0
Reputation: 18870
I assume that the server in question already has PHP installed, as you say you have PHP elsewhere in the site.
Are you saving the HTML page as a PHP page, i.e. with the .php extension?
Upvotes: 0
Reputation: 944321
The server needs to be told to run the document through the PHP engine.
This is usually done by giving the file a .php
extension.
You can also configure the server to pass files other other file extensions or specific files through PHP, but how you do that depends on the server (and is a matter of server configuration, not programming).
Upvotes: 4