【问题标题】:URL Rewrite web.config add fake folder between domain and pagesURL Rewrite web.config 在域和页面之间添加假文件夹
【发布时间】:2019-09-03 13:35:29
【问题描述】:

只是一个简单的问题。 我有一个域 website.com,并且这个页面有以国家代码命名的特定页面。

  • website.com/英国
  • website.com/fr
  • website.com/我们
  • ...

我已经在我的 web.config 文件上创建了规则,并使用以下 URl 重写:

 <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
    <match url= "^([^/]+)/?$"/>          
      <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
     <action type="Rewrite" url="ContactUs.php?lang={R:1}" />
  </rule>

页面是在 PHP 中生成的,名为 lang 的变量用于显示选择的页面并存在于 URL 中。

我想在我的域和页面之间添加 "contact/"

  • website.com/联系方式/uk
  • website.com/contact/fr
  • ...

我有以下规则:

<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
   <match url="contact([^/]+)/?$"/>
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
    <action type="Rewrite" url="ContactUs.php?lang={R:1}"/>
 </rule>

任何人都可以向我解释我不明白的地方, 谢谢

【问题讨论】:

    标签: azure iis web-config


    【解决方案1】:

    你的正则表达式有点错误。

    ^contact\/([a-z]+)\/?$
    

    这应该可以满足您的需要,假设您的所有国家/地区代码都是字母。

    【讨论】:

    • 完美!谢谢!
    【解决方案2】:

    您要先将 website.com/uk 重定向到 website.com/contact/uk,然后将 website.com/contact/uk 重写为 ContactUs.php?lang=uk?

    如果您愿意这样做,您可以使用以下 URL 重写规则:

    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
       <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="www.sample2.com" />
                            <add input="{REQUEST_URI}" pattern="^/[a-zA-Z]+$" />
          </conditions>
        <action type="Redirect" url="http://{HTTP_HOST}/contact{C:0}" />
     </rule>
                  <rule name="RewriteUserFriendlyURL2" stopProcessing="true">
       <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_URI}" pattern="/contact/([a-z]+)" />
          </conditions>
        <action type="Rewrite" url="ContactUs.php?lang={C:1}" />
     </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多