1
votes

I've seen many questions on how to go from an .htaccess to a web.config. There don't seem to be many questions about going the other way, from web.config to .htaccess.

Here's the configuration file I need to convert into an .htaccess file:

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
  <system.webServer>
    <rewrite>
        <rules>
            <rule name="Imported Rule 1" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{R:1}" pattern="^(cms|css|files|images|js|themes|index\.php)" negate="true" />
                </conditions>
                <action type="Rewrite" url="/index.php/{R:1}" />
            </rule>
        </rules>
        <rewriteMaps>
            <rewriteMap name="login">
                <add key="http://server/cms/index.php?S=0&amp;D=cp&amp;C=login&amp;M=login_form" value="http://server/login" />
            </rewriteMap>
        </rewriteMaps>
    </rewrite>
    <httpErrors>
        <remove statusCode="403" subStatusCode="-1" />
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="/error404" responseMode="ExecuteURL" />
        <error statusCode="403" prefixLanguageFilePath="" path="/error403" responseMode="ExecuteURL" />
    </httpErrors>
 </system.webServer>
</configuration>

There are a few parts of this that I'm not sure about, and that's what's preventing me from figuring this out on my own.

The first is the 'conditions' part of the first rule. I'm not sure how to convert that to an .htaccess rule.

The second is the 'httpErrors' section. I'm probably just having a brain fart, but I can't remember how to do that in an .htaccess file.

Any help is much appreciated!

Cheers.

1
Try reverting thisEmmanuel N

1 Answers

1
votes

Here is everything except RewriteMap, which you cannot do in .htaccess

RewriteEngine On
RewriteBase /

#rule name="Imported Rule 1" stopProcessing="true"
RewriteCond $1 !^/(cms|css|files|images|js|themes|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

#equivalent of your rewritemap rule, which you cannot do in htaccess
RewriteCond %{HTTP_HOST} ^server$
RewriteCond %{QUERY_sTRING} ^S=0&D=cp&C=login&M=login_form$ [NC]
RewriteRule ^cms/index\.php$ /login [L,R=301]


#httpErrors will server up error404 as file: change to html if that is file you want
ErrorDocument 404 /error404
ErrorDocument 403 /error403