将 web.config 文件转换为 .htaccess

Converting web.config file to .htaccess

谁能帮我把这个 web.config 文件转换成 .htaccess

我可以找到几个在线转换器将 .htaccess 转换为 web.config,但 none 将 web.config 转换为 .htaccess

<rules>
    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
        <match url="^themes/sets\.cfm$" />
        <conditions>
            <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
            <add input="{QUERY_STRING}" pattern="^set=([^=&amp;]+)$" />
        </conditions>
        <action type="Redirect" url="themes/sets/{C:1}" appendQueryString="false" />
    </rule>
    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
        <match url="^themes/sets/([^/]+)/?$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="themes/sets.cfm?theme={R:1}" />
    </rule>
    <rule name="RedirectUserFriendlyURL2" stopProcessing="true">
        <match url="^set\.cfm$" />
        <conditions>
            <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
            <add input="{QUERY_STRING}" pattern="^set=([^=&amp;]+)&amp;name=([^=&amp;]+)$" />
        </conditions>
        <action type="Redirect" url="set/{C:1}/{C:2}" appendQueryString="false" />
    </rule>
    <rule name="RewriteUserFriendlyURL2" stopProcessing="true">
        <match url="^set/([^/]+)/([^/]+)/?$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="set.cfm?set={R:1}&amp;name={R:2}" />
    </rule>
</rules>

提前致谢。

我有点惊讶你的 "friendly url 2" 块没有产生无限重定向循环(也许 IIS 自己处理这个,我不知道)。

无论如何,使用 Apache 和 mod_rewrite,您只需 "translating" 您的规则就会出现无限循环。

注意:"friendly url 1" 可以按原样翻译,因为重定向和重写并不完全针对同一目标)。

你的 htaccess 应该是这样的

RewriteEngine On
Options -MultiViews

# RedirectUserFriendlyURL1
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} ^set=([^&=]+)$
RewriteRule ^themes/sets\.cfm$ /themes/sets/%1? [R=301,L]

# RewriteUserFriendlyURL1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^themes/sets/([^/]+)/?$ /themes/sets.cfm?theme= [L]

# RedirectUserFriendlyURL2
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/set\.cfm\?set=([^&\s]+)&name=([^&\s]+)\s [NC]
RewriteRule ^ /set/%1/%2? [R=301,L]

# RewriteUserFriendlyURL2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^set/([^/]+)/([^/]+)/?$ /set.cfm?set=&name= [L]