IIS规则转换为.htaccess规则

时间:2013-04-17 10:43:20

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

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

  1. 从文件名
  2. 中删除.php扩展名
  3. 重写变量。
  4. 因此,服务器会将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规则吗?

1 个答案:

答案 0 :(得分: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]