【发布时间】:2011-07-19 17:00:57
【问题描述】:
我目前有一个 Movable Type 博客,其中的页面没有任何文件扩展名...所以 example.com/entries/this-is-my-entry
我添加了DefaultType text/html,因此 Apache 知道文件末尾是否没有任何扩展名以显示为 HTML。效果很好。
现在的问题是我在 HTML 中有 PHP 代码。如果没有扩展,页面将不会呈现 PHP 代码。但是,当我发布带有 .html 扩展名的条目时……PHP 代码可以完美运行。
我有AddHandler php5-script .html 告诉 Apache 在 HTML 文件中显示 PHP。我猜,如果没有任何文件扩展名,它不知道渲染 PHP 代码,因为它期待具有 .html 扩展名的文件......有没有办法说任何文件不有扩展可以用PHP吗?
【问题讨论】:
-
您应该始终为文件添加扩展名。如果您想要省略扩展名的 URL,请使用
mod_rewrite。 -
@KingCrunch 为什么没有扩展名的文件不好?缺点是什么?根据W3C:
What to leave out - File name extension. This is a very common one. "cgi", even ".html" is something which will change. You may not be using HTML for that page in 20 years time, but you might want today's links to it to still be valid. The canonical way of making links to the W3C site doesn't use the extension.(当然,他们仍然可以谈论使用重写,但保留实际文件名的扩展名)。 -
@chown 我说的是(物理)文件,而不是浏览器地址栏中显示的内容。
标签: php html linux apache movabletype