Php:使用web.config重写URL

时间:2015-04-20 13:13:53

标签: php html .htaccess iis url-rewriting

这是我的第一个PHP应用程序,我在本网站使用 .html .php 页面。如果用户浏览 mysite.com/users/?abc123 ,它会在普通html页面 mysite.com/users/上成功加载id为“ abc123 ”的用户的详细信息index.html 通过Ajax。现在,我的任务是从网址中删除?,以便用户浏览 mysite.com/users/abc123 ,然后 mysite.com/users/index.html?abc123 应该成功提供详细信息。

我跟着this link并将此规则添加到我的web.config中,但这似乎没有用,我收到了:

  

错误:HTTP错误404.0 - 未找到

<rule name="Remove question mark" patternSyntax="Wildcard" stopProcessing="true">
  <match url="*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^users/(.*)$" />
  </conditions>
  <action type="Redirect" url="users/?{R:0}" redirectType="Permanent" />
</rule>

请记住以下问题来帮助我:

  1. 我只能使用web.config进行URL重写(以保持简单)
  2. 我要重写URL的页面是.HTML而不是.PHP(如果重要)
  3. 我在IIS 8中本地测试我的PHP站点,配置为提供PHP

1 个答案:

答案 0 :(得分:1)

这应该有效

<rule name="Remove question mark" stopProcessing="true">
  <match url="^/?users/([^/]+)$" ignoreCase="true" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Rewrite" url="/users/index.html?{R:1}" />
</rule>
相关问题