0

First of all, I am not trying to run php within a js script, there is a similar question on here that refers to a user trying to run php from inside a js script.

I have added many combinations of

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

AddHandler x-httpd-php .html

to the .htaccess file in a higher level directory containing the .html file I want to run php in. This has not worked. (I am open to trying new combinations)

The is either not read at all or commented out when viewing the source in broswer.

My question is how to get to be run inside of an html file OR is there a better way to include php functionality in an html document without having the code in the same document.

Additionally my host uses cpanel if this helps anything.

I can elaborate on anything I need to, thanks in advance.

SmashCode
  • 4,227
  • 8
  • 38
  • 56

1 Answers1

1

You can try to use mod_rewrite for that task:

RewriteEngine On
RewriteRule ^(.*).html index.php [QSA]
insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
  • Do I lose any html functionality by rewriting as .php rather than having php be read in the html? – SmashCode Feb 17 '13 at 21:49
  • 1
    No, of course not. I'm not sure why you aren't just using a PHP file to begin with. You can mix HTML, JS, CSS, and PHP in a .php page. – SISYN Feb 17 '13 at 22:01
  • There are a couple pages that I can have as .php files, but some of the pages on the website I need to have as html for search engine hits. I'm starting to wonder if I should even have the php code in the html document, it will be visible won't it? – SmashCode Feb 17 '13 at 22:09
  • As all PHP code gets executed no visitor will see any of it. The rewrite rule helps to get nice URLs that ends with `.html` and you have still the possibility to show dynamic content. – insertusernamehere Feb 17 '13 at 22:10
  • Will it affect the indexing done by search engine crawlers? That's the main thing I'm worried about. I'm working on this for someone who is very concerned with being competitive on search engine results? – SmashCode Feb 17 '13 at 22:31
  • I'd say that most relevant is the content that is delivered and also the URL. So it's a good practice to not change an already published URL. You can find lots of informations about "clean URLs" and slugs, good URL lengths, URL naming etc. here on Stack Overflow. – insertusernamehere Feb 17 '13 at 22:37
  • Also, thank you for taking the time to answer insertusernamehere, +1 for helpful information regardless of this fixing it or not. – SmashCode Feb 17 '13 at 22:37
  • 1
    SEO is a very broad field and there are many facts and also many myths. But as I said, take some time and read some articles about "SEO friendly URLs" and than decide which is the best way for you to create them. Maybe you end up with something that has no file extension at all, like `domain.com/products/item-1`. – insertusernamehere Feb 17 '13 at 22:41