keith
keith

Reputation: 37

PHP code in HTML without a file extension

I currently have a Movable Type blog where the pages do not have any file extensions...so example.com/entries/this-is-my-entry

I added DefaultType text/html, so Apache knows if there isn't any extension on the end of the file to display as HTML. That works great.

Now the problem is I have PHP code in the HTML. The page won't render the PHP code if there is no extension. However, when I publish the entries with a .html extension....the PHP code works perfectly.

I have AddHandler php5-script .html to tell Apache to display PHP in the HTML files. I'm guessing, if there isn't any file extension, it doesn't know to render the PHP code, because it is expecting files with a .html extension...is there a way to say any file that doesn't have an extension can use PHP?

Upvotes: 2

Views: 1777

Answers (3)

BrianC
BrianC

Reputation: 10721

I'm doing the same implementation for my personal MT blog, with the entries having no file extension. (The theory being that I could switch to other techniques in the future without being hampered by extensions like .html, .php, etc.)

You can accomplish this by setting your default type to be PHP:

DefaultType application/x-httpd-php

All PHP files are interpreted at first as HTML, so this works even for files with no PHP in them.

Upvotes: 4

Aleks G
Aleks G

Reputation: 57316

Maybe you can try using <FileMatch> directive? Something like

<FilesMatch "^[^\.]$">
    ForceType application/x-httpd-php
</FilesMatch>

Upvotes: 1

Ianus Chiaroscuro
Ianus Chiaroscuro

Reputation: 229

There is nothing directly corresponding to DefaultType for AddHandler, but you can hack around it in a fairly ugly way:

<FilesMatch "^(?!.*\..+)">
    SetHandler php5-script
</FilesMatch>

Upvotes: 0

Related Questions