【问题标题】:Problems using URL Rewrite in IIS7 for friendly URLs在 IIS7 中使用 URL 重写以获取友好 URL 的问题
【发布时间】:2011-09-27 11:56:56
【问题描述】:

我正在尝试使用 URL 重写在我的 IIS7 服务器中创建一些重写规则。 例如,我有 url mydomain.com/data.php?id=1,我想将其转换为 mydomain.com/archive/1

目前我有:

    <rule name="Ugly to friendly" stopProcessing="true">
  <match url="^data\.php$" />
  <conditions>
      <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
      <add input="{QUERY_STRING}" pattern="^([^=&amp;]+)=([^=&amp;]+)$" />
  </conditions>
  <action type="Redirect" url="archive/{C:2}" appendQueryString="false" /> 
</rule>

<rule name="Friendly to ugly" stopProcessing="true">
  <match url="archive/(.+)" />
  <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="data.php?id={R:1}" />
</rule>

但它不起作用(读作“页面在没有该规则的情况下可以正常显示,但是当添加规则时不显示 css/imgs)。 奇怪,因为萤火虫告诉我一切都好(200 OK)(也许它也会混淆?)

问候

【问题讨论】:

    标签: iis-7 url-rewriting


    【解决方案1】:

    抱歉,代码没问题。我的页面(data.php)是错误的。与其让所有 imgs/css 使用 php 文件中的相对路径,我应该使用根目录中的相对路径来编写它们。

    我的意思是,我应该写“img src="/folder1/fol”而不是“img src="../../test.jpg"。

    注意路径开头的“/”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 2014-10-02
      • 2013-05-24
      • 2015-07-24
      • 2013-02-02
      • 1970-01-01
      相关资源
      最近更新 更多