【问题标题】:IIS Rule Convert To .htaccess RuleIIS 规则转换为 .htaccess 规则
【发布时间】:2013-04-10 02:12:02
【问题描述】:

我需要一些帮助来编写一个 .htaccess 规则:

  1. 从文件名中删除了 .php 扩展名
  2. 重写变量。

因此,像www.example.com/contact-us/456/789 这样的网址将被服务器解释为www.example.com/contact-us.php?a=123&b=456&c=789

以下 IIS web.config 规则很有效(使用重写映射):

<rule name="Dynamic Rewriting" stopProcessing="true">
    <match url="^([^/]+)(?:/?([^/]+)?)(?:/?([^/]+)?)(?:/?([^/]+)?)/?$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{DynamicRewriting:{R:1}}" pattern="(.+)" />
    </conditions>
    <action type="Rewrite" url="/{C:1}.php?page={C:1}&amp;a={R:2}&amp;b={R:3}&amp;c={R:4}" />
</rule>

<rewriteMap name="DynamicRewriting">
    <add key="contact-us" value="contact-us" />
</rewriteMap>

谁能告诉我我需要的 .htaccess 规则吗?

【问题讨论】:

    标签: .htaccess iis mod-rewrite web-config


    【解决方案1】:

    试试:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^/([^/]+)
    RewriteCond %{DOCUMENT_ROOT}/%1.php -f
    RewriteRule ^/?([^/]+)(?:/?([^/]+)?)(?:/?([^/]+)?)(?:/?([^/]+)?)/?$ /$1.php?page=$1&a=$2&b=$3&c=$4 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 2020-03-08
      • 2011-04-25
      • 1970-01-01
      • 2012-08-22
      相关资源
      最近更新 更多