2017-12-07 52 views
0

すでにアンダースコアがある場合は、末尾のアンダースコアをURLに追加するURLRewriteを作成しようとしています。 URLへhttps://localhost/pdf/mypdf_.pdf 書き換え:https://localhost/pdf/mypdf__.pdfURLに後ろのアンダースコアを追加するURLRewriteルール

、着信URLはアンダースコアを持っていない場合は、ルールが実行すべきではありませんこれは、着信URL PDFファイル

のために特別です。

  <rule name="Init PDF Rules"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{REQUEST_URI}" pattern="^.*_.pdf.*$" /> 
       </conditions> 
       <action type="Redirect" url="{C:1}_{C:2}" /> 
      </rule> 

は、私はいくつかのスタック交換質問を通過しようとしましたが、完璧なルールを記述することができませんでした。

答えて

0

次のルールは、名前がで、末尾がの既存のファイルに対してのみ機能します。

<rule name="rewrite pdf file names ending with a _"> 
    <match url="^(.*/)?(.*?)([^_]_)(\.pdf)$" /> 
    <conditions logicalGrouping="MatchAll"> 
     <!-- skip rewriting if the path is a directory or an existig file --> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="{R:1}{R:2}{R:3}_{R:4}" /> 
</rule> 
関連する問題