【发布时间】:2013-08-19 01:29:57
【问题描述】:
我正在尝试从 url 中删除扩展名 .php,以便 mysite.com/home.php 可以作为 mysite.com/home 工作。
我在 1and1.com 上托管我的网站,我问他们是否打开了 Rewrite 引擎,他们说对于运行 IIS 7.5 的 Windows 服务器,它没有打开,我可以用一些web.config 文件中的代码。
我找不到开启重写规则的代码。
以下是我尝试用来重写 url 的内容。但我收到错误 500.19。
真的有办法在 web.config 文件中开启重写功能吗?
web.config 文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="home.php" />
<add value="index.html" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="rewrite php">
<!--Removes the .php extension for all pages.-->
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).php" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
【问题讨论】:
-
stackoverflow.com/questions/18275740/… 或许可以使用类似的东西来删除.php
标签: web-config rewrite iis-7.5 windows-server