54

分かりにくい URL をよりわかりやすい URL にリダイレクトしようとしています。これらの URL は.aspx?cid=3916、カテゴリ名ページごとに異なる最後の桁で終わります。代わりににリダイレクトしたいCategory/CategoryName/3916web.configファイルでこれを試しました:

<location path="Category.aspx?cid=3916">
<system.webServer>
  <httpRedirect enabled="true" destination="http://www.site.com/Category/CategoryName/3916" httpResponseStatus="Permanent" />
</system.webServer>

延長だけでは終わらないので、うまくいきませんでした。これを機能させる簡単な方法はありますか?IIS 7.5 を使用しています。

4

3 に答える 3

58
  1. 古いページが存在するディレクトリでweb.configを開きます
  2. 次に、次のように古いロケーションパスと新しい宛先のコードを追加します。

    <configuration>
      <location path="services.htm">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://domain.com/services" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
      <location path="products.htm">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    </configuration>
    

必要な数のロケーションパスを追加できます。

于 2012-05-01T15:30:30.870 に答える
27

単純なを使用するのではなく、 URL Rewriteのようなものを見て、 URLをよりユーザーフレンドリーなものに書き換えたいと思うかもしれませんhttpRedirect。次に、次のようなルールを作成できます。

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Rewrite to Category">
        <match url="^Category/([_0-9a-z-]+)/([_0-9a-z-]+)" />
        <action type="Rewrite" url="category.aspx?cid={R:2}" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
于 2012-05-01T15:31:10.450 に答える