简体   繁体   中英

Using “.html” to link to a .html.php file - what's the magic?

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.)

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.

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM