将 shtml 页面更改为 php
我有一个带有 shtml 扩展名的页面的网站,主要是为了让菜单导航栏与 SSI 正确显示。我现在正在添加一个带有 php 的页面,为了使该页面正常工作,我给了它一个 php 扩展名,这会导致菜单不再显示。坦率地说,我还发现 shtml 扩展对于大多数使用我的网站的人来说是一个奇怪的扩展。如果可能的话,我想将所有页面更改为 php 扩展名,但是如果我不再使用 shtml 扩展名,如何重新格式化我的 SSI 以正确显示?
当前感兴趣的代码是
I have a site with pages with shtml extension, primarily done to have menu navbar display corrctly with SSI. I now am adding a page with php, and to have this page work properly I have given it a php extension, which causes the menu to no longer display. I also frankly find the shtml extension to be an odd one for most who use my site. I would like to change to php extension for all pages if possible, but how do I reformat my SSI to display properly if I no longer use the shtml extension?
The current code of interest is <!--#include virtual="/Navbar.shtml" -->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将服务器端包含代码更改为
并将
Navbar.shtml
重命名为Navbar.php
Require 意味着存在错误,如果缺少 Navbar.php,页面根本无法加载。
您还可以使用 include,它类似,但将允许加载页面。请阅读以下手册页以获取有关 include 和 require 的更多信息。
http://www.php.net/manual/en/function.include.php
http://php.net/manual/en/function.require.php
希望这有帮助:)
It should just be a matter of changing your Server side include code to
<?php require "/Navbar.php" ?>
and renaming
Navbar.shtml
toNavbar.php
Require means that there is an error and the page wont load at all if Navbar.php is missing.
You could also use include, which is similar, but will allow the page to load. Read the following manual pages for more info on include and require.
http://www.php.net/manual/en/function.include.php
http://php.net/manual/en/function.require.php
Hope this helps :)
到
to
如果您使用 SSI 包含本地文件,则将使用静态源文件 - 在本例中为未解析的 PHP 源代码。
您必须执行远程包含才能使其工作(类似于
,具体取决于服务器配置)。这不是最佳选择,因为会启动新的服务器请求和 PHP 实例。
最好为此放弃 SSI,并使用 PHP 包含,如 @Alin 所示。
If you include a local file using SSI, the static source file will be used - in this case, the unparsed PHP source code.
You would have to do a remote include for this to work (something like
<!--#include virtual="http://localhost/Navbar.shtml" -->
, depending on server configuration). That is not optimal, because a new server request, and a PHP instance, are started.It would be better to drop SSI for this, and use a PHP include as @Alin shows.