将web.config文件转换为.htaccess

时间:2012-03-06 21:08:08

标签: .htaccess iis web-config

我正在寻找一种方法将我的IIS重写规则转换为.htaccess文件。我找不到任何自动执行此操作的工具,而我所能得到的只是500内部服务器错误。

web.config文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="RemoveTrailingSlash" stopProcessing="true">
                    <match url="^(.*?)/+$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" />
                </rule>
                <rule name="HaltOnTinyMCE" stopProcessing="true">
                    <match url="^tinymce/.*$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="None" />
                </rule>
                <rule name="RewriteContent" enabled="true" stopProcessing="true">
                    <match url="^.*\.(gif|jpg|png|css|js|swf|txt|xml)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="domains/{HTTP_HOST}/{R:0}" appendQueryString="true" logRewrittenUrl="false" />
                </rule>
                <rule name="RewritePages" enabled="true">
                    <match url="^.*$" ignoreCase="true" negate="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="index.php" logRewrittenUrl="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

我最好尝试手动转换它仍然给我500内部服务器错误。有什么建议吗?

RewriteEngine on

RewriteCond /+$
RewriteRule ^(.*?)/+$ http://{HTTP_HOST}/$1 [R=301,L]

RewriteCond ^tinymce/.*$
RewriteRule ^(.*)$ $1 [L]

RewriteCond \.(gif|jpg|png|css|js|swf|txt|xml)$
RewriteRule ^.*\.(gif|jpg|png|css|js|swf|txt|xml)$ domains/{HTTP_HOST}/$1 [L]

RewriteRule ^.*$ index.php

提前致谢!

1 个答案:

答案 0 :(得分:2)

你正朝着正确的方向前进,但是有一些错误和不需要的东西。这就是我想出的:

RewriteEngine on
RewriteBase /

#remove tailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 [R=301,L]

# stop rules below from being applied if url starts with tinymce/
RewriteRule ^tinymce/.*$ - [L]

#rewrite images etc. to domains folder (unless url already starts with domain/)
RewriteCond $0 !^domains/
RewriteRule ^.*\.(gif|jpg|png|css|js|swf|txt|xml)$ domains/%{HTTP_HOST}/$0 [L]

#catch all other (I added 2 rewriteconds, to prevent rewriting existing files (including index.php))
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php