2

I am totally new to php coding and my teacher told us that PHP files should be renamed with .php extension for it to work. But I have files in the serve with .htm extension, which I used with Google Analytics and Search Console, so now I don't want to change the extension to all my 5 five pages as I would make a huge chaos out of it. So is there a way I can insert php code into my html pages and still use it with .htm extension?

Thank you!

arthrax
  • 161
  • 2
  • 4
  • 12
  • I am not sure what you are asking, but you can use `` – samayo Nov 27 '15 at 00:36
  • I'm not sure about your question too. However, you can do the reverse: insert html code into your html pages. Basically you create a PHP file for each HTML file and copy the contents there. – jackeblagare Nov 27 '15 at 00:39
  • It depends on server/ htaccess settings. You can have .html pages that parse the php the same. But in most cases when wanting search engine optimized, you have your htaccess file call a .php but have the .html extension. – Evan Carslake Nov 27 '15 at 01:04

4 Answers4

5

You want to write PHP codes within the .HTM / .HTML files

all you have to do is the add the following lines to your httpd.conf

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

note: restart your apache or rehash it so that the configurations take effect

Nur Ys
  • 133
  • 1
  • 8
3

Yes, you can use php code inside .html files, But you need to config the websever. In Apache you can config like this:

# Interpret both .php & .html as PHP:
AddHandler php5-script .php .html

As reference look this answer here

Community
  • 1
  • 1
Vinícius Fagundes
  • 1,983
  • 14
  • 24
-4

Hi you cannot run PHP withouth .php extension files. But you can work with friendly-urls.

You can do something like that

In your .htaccess file

RewriteEngine on
RewriteRule ^/example/([0-9]+)\ /example.php?id=$1

And this maps requests from

/example.php?id=contact

to

/example/contact

You can find more about it in Google typing "How I can work with url firendly in php".

Met El Idrissi
  • 169
  • 1
  • 16
-4

Short answer: No.

Explained: The .php tells the server that the file has php information and needs to run the select code as php. Otherwise it'll run as normal html and won't run your code.

You can link to a separate .php page when something requires the php code. Yet if it's for a page with dynamic loading then you just have to change the extension.

Vexxoz
  • 88
  • 8
  • 5
    Not my downvote, but it's possible to configure your server to run PHP content in `.html` files. – Qirel Nov 27 '15 at 01:30