加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Php:使用web.config重写URL

发布时间:2020-12-13 15:55:24 所属栏目:PHP教程 来源:网络整理
导读:这是我的第一个 PHP应用程序,我在本网站使用.html和.php页面.如果用户浏览mysite.com/users/?abc123,它会通过Ajax在普通的html页面mysite.com/users/index.html上成功加载id为’abc123’的用户的详细信息.现在,我的任务是删除?从URL中,如果用户浏览mysite.c
这是我的第一个 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读