Answer the question
In order to leave comments, you need to log in
How to convert redirects from IIS web.config to Apache .htaccess?
Hello.
In the process of migrating an ancient PHP site from Windows server + IIS to Linux + Apache + .htaccess, there was a need to translate several redirects from the IIS web.config format to Apache .htaccess.
I managed to rewrite a few of them myself, but there are some that I can’t handle.
Help me please.
web.config rules:
<rule name="Rule1" enabled="true" stopProcessing="true">
<match url="^switch\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^lang=([^=&]+)$" />
</conditions>
<action type="Redirect" url="switch/{C:1}" appendQueryString="false" />
</rule>
<rule name="Rule2" enabled="true" stopProcessing="true">
<match url="^switch/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="switch.php?lang={R:1}" />
</rule>
<rule name="Rule3" stopProcessing="true">
<match url="^zone-client/index\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="zone-client/index" appendQueryString="false" />
</rule>
<rule name="Rule4" stopProcessing="true">
<match url="^zone-client/index$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="zone-client/index.php" />
</rule>
<rule name="Rule5" stopProcessing="true">
<match url="^index\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^slug=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="Rule6" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?slug={R:1}" />
</rule>
<rule name="Rule7" stopProcessing="true">
<match url="^index\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^slug=([^=&]+)&details=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="Rule8" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?slug={R:1}&details={R:2}" />
</rule>
#Rule1
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^translation\.php(.*) /translation? [R=302,L]
#Rule2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^translation(.*) /translation.php [R=302,L]
#Rule3
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} ^lang=&$
RewriteRule ^switch\.php(.*) /switch/%1 [R=302,L,B]
#Rule4
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^zone-client/index(.*) /zone-client/index.php [R=302,L]
#Rule5
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} ^slug=&$
RewriteRule ^index\.php(.*) /%1 [R=302,L,B]
#Rule6
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ /index.php?slug=$1 [R=302,L]
#Rule7
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} ^^slug=&;details=&$
RewriteRule ^index\.php(.*) /%1/%2 [R=302,L,B]
#Rule8
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)/?$ /index.php?slug=$1&details=$2 [R=302,L]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question