tags:

views:

152

answers:

5

This is more a question of curiosity.

So I was reading a chapter from (Sitepoint's latest PHP/MySQL book), in which the author mentioned using the extension ".html.php" to indicate files that has both HTML and PHP. I tried it out, and discovered this:

If I have a file "fileA.html.php", and somewhere in "fileB.html" I have a link thusly:

<a href="fileA.html">Text text</a>

I'm able to link directly to fileA.html.php, correctly parsed, even though logic, and the book, tells me that I should have written href="fileA.html.php".

Anyone have any idea what PHP function does this, or if it's just standard PHP behavior? (Not that I'm complaining, it's just something my client noted and thought was cool.)

+3  A: 

You'd have to have your server configured to do that. If you're using Apache there are numerous ways to accomplish that with htaccess rewrite rules or other processors.

But if you're going to go to those lengths, why require the html at all? I'd say either serve the file with the appropriate extension type (in that case just .php) or make it extensionless or extension-optional. The only reason to do it at all is to make it easier on your users. There's no advantage for changing the extension otherwise.

Gabriel Hurley
+1 for steering toward language-agnostic URLs. curagea, you can point to "fileA/" and put an index.php in the directory, and most web servers (to my knowledge) will serve "fileA/index.php" automatically. If you ever change to .html or .anything, you shouldn't have to change the URL.
l0b0
It was my .htaccess. I actually didn't write it, so I was unaware of the line "AddHandler application/x-httpd-php .htm .php". I only added the .html so that I can tell that there's also HTML code in my PHP files (whereever it may apply). As to the index.php trick, I'm aware of it, but am only using it in limited quantities because it's a pretty simple, small site.
curagea
A: 

I have never heard of such behavior. The only thing that comes to mind is some kind of htaccess rewrite mod

Ori Cohen
+5  A: 

PHP is not at cause. Apache probably has mod_spelling enabled and is auto-correcting the link. That behavior will not be consistent between servers with different configurations.

Andrew Moore
A: 

I typically put this in the .htaccess file:

<Files *.html>
AddHandler application/x-httpd-php .html .htm .php
</Files>

This means to treat .html files as if the were .php files, in essence.

Chris Arguin
A: 

You can also add on your httpd.conf

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

All your .html files can now parse inside.

Which I think is cooler.

HTH

Louie Miranda