在windows webmatrix2服务器的html页面中嵌入php

时间:2012-10-01 04:53:22

标签: php html .htaccess web-config

我想在我的godaddy linux托管网站上的html页面中嵌入php代码。 我知道howtos将通过编辑我的方式指导我如何在godaddy上做到这一点 .htaccess文件。

我的问题是我想在windows webmatrix2下本地开发

在运行iis或webmatrix作为服务器的Windows服务器下需要做什么?  我的godaddy帐户是在linux下托管的,但是我使用webmatrix在windows下开发。

我发现解决方案无效。

1)根据一个来源,将这些行添加到 applicationhost.config 文件

<add name="PHP53_via_FastCGI_html" path="*.html" 
   verb="GET,HEAD,POST" modules="FastCgiModule" 
   scriptProcessor="C:\Program Files (x86)\iis express\PHP\v5.3\php-cgi.exe"
   resourceType="Either" />

在iisexpress目录下。他们崩溃了整个本地网站。

2)在Webmatrix中,在网站的 web.config 文件中添加此重写规则。

<system.webServer>
  <rewrite>
    <rules>
        <rule name="REWRITE_TO_PHP">
        <match url=".html" />
        <conditions logicalGrouping="MatchAll" />

        <action type="Rewrite" url=".php" />
            </rule>
    </rules>
</rewrite>
... more code 

3)或在 web.config

中尝试此操作
<rewrite>
    <rules>

        <rule name="REWRITE_TO_PHP">
        <match url="*.html" />
        <conditions logicalGrouping="MatchAll" />
        <action type="Rewrite" url="{"*.Php"} />

    </rule>
</rewrite>

4)或在 web.config

中尝试此操作
<handlers>
<add name="html via php cgi" path="*.html" verb="*" modules="FastCgiModule" 
scriptProcessor="C:\Program Files\Php\php-cgi.exe" 
resourceType="Unspecified" />
</handlers> 

以上都不适合我。 我知道以上所有这些都是很多信息。这是我在漫长的网络搜索中找到的所有内容。我不是经验丰富的系统编码器。我只需要一些东西 这工作,将允许我开始在Windows上的HTML编码PHP。关键突破 如果我开始看到我的php在关键字颜色中显示并且有webtrix intellisense 工作! 智能感知很棒! 谢谢。

3 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。

解决方案:使用以下代码在网站的根目录中创建 web.config 文件:

<configuration>
    <system.webServer>
    <rewrite>
        <rules>
            <rule name="GeneralRewrite" stopProcessing="true">
                <match url="^(.*).html$" ignoreCase="true" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="{tolower:{R:1}}.php" />
            </rule>
        </rules>
    </rewrite>
    </system.webServer>
</configuration>

答案 1 :(得分:0)

在你的web.config文件中你应该有

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <handlers>
        <add name="PHP_via_FastCG1" path="*.htm" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP5.5\php-cgi.exe" resourceType="Either" />
        <add name="PHP_via_FastCG2" path="*.html" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP5.5\php-cgi.exe" resourceType="Either" />
    </handlers>
</system.webServer>
</configuration>

其中scriptProcessor =&#34; C:\ PHP5.5 \ php-cgi.exe&#34;取决于你的php实际存储在系统中的位置。您可以使用phpinfo()获取有关系统可能位置的一些提示。

答案 2 :(得分:-1)

好吧,我认为你想要做的只适用于没有webmatrix的apache。有关详细信息,请阅读:Php tags in .html files don't work in WebMatrix