简体   繁体   English

SSI包括不在服务器上工作但在本地工作

[英]SSI includes not working on server but working locally

I'm developing a website locally with USBWebServer (Apache, PHP, MySql) and I wanted to use SSI, so I could include stuff like header, footer and so on. 我正在使用USBWebServer在本地开发一个网站(Apache,PHP,MySql),并且想使用SSI,因此可以包含诸如页眉,页脚等内容。

In my .htaccess I have put following directives: 在我的.htaccess文件中,我输入了以下指令:

Options +Includes

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

I have main index.shtml and inside it I have directives: 我有main index.shtml,里面有指令:

<!--#include virtual="./files/navbar.shtml" -->
<!--#include virtual="./files/contact.shtml" -->

and it works just fine. 而且效果很好。

However, when I upload site to my webserver, with the same directives in .htaccess, index.shtml cannot include anything. 但是,当我使用.htaccess中的相同指令将网站上传到Web服务器时,index.shtml无法包含任何内容。

My current workaround is to change index.shtml to index.php and to use php includes like: 我当前的解决方法是将index.shtml更改为index.php并使用php包括:

<?php
virtual('./files/navbar.shtml');
?>

, but I would like to know why SSI doesn't work as expected on the server and what can I do to make it work with .shtml? ,但是我想知道为什么SSI无法在服务器上按预期方式工作,以及如何使其与.shtml一起使用?

Assuming that the webserver on you server is an 2.x Apache: You have to enable the Include-module. 假设您服务器上的Web服务器是2.x Apache:您必须启用Include-module。 If you have admin-rights on the server you can do it yourself by executing as root 如果您在服务器上具有管理员权限,则可以通过以root用户身份执行自己来执行此操作

a2enmod include

and restarting the webservice with "service apache2 restart" or "/etc/init.d/apache2 restart". 然后使用“ service apache2 restart”或“ /etc/init.d/apache2 restart”重新启动Web服务。
If not than you have to ask your admin or serverprovider. 如果不是,则必须询问管理员或服务器提供商。 Also the usage of .htaccess may be limited by the server configuration, see if allow overide or similar options are configured (or again: ask your admin). 另外,.htaccess的使用可能会受到服务器配置的限制,请查看是否配置了允许覆盖或类似选项(或再次:询问管理员)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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