微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Php:使用web.config重写URL

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

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

Error: HTTP Error 404.0 – Not Found

<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>

请帮助我解决以下问题:

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

解决方法

这应该有效

<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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐