Jiri Kriz
Jiri Kriz

Reputation: 1

.htaccess (mod_rewrite) and Microsoft azure

I have this code in my .htaccess and i need this transform to microsoft azure hosting, because it doesnt work.

    RewriteEngine On

    RewriteCond %{THE_REQUEST} /index\.php[?/\s]
    RewriteRule ^index\.php$ /en/ [R=301,L]

    RewriteCond %{THE_REQUEST} /index_cz\.php[?/\s]
    RewriteRule ^index_cz\.php$ /cz/ [R=301,L]

    RewriteRule ^/en/?$ index.php [NC,L]
    RewriteRule ^cz/?$ index_cz.php [NC,L]

Could someone help me? Thanks guys

Upvotes: 0

Views: 2802

Answers (2)

Gary Liu
Gary Liu

Reputation: 13918

I build a simple PHP project to simulate your rewrite rules situation.

The root directory:

enter image description here

And the content of index.php in folder like ‘en’ is:

echo "response in en folder <br />"; var_dump($_GET); And I leverage @ Joe Raio’s answer and make a little modification:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rule 1m" stopProcessing="true">
                    <match url="^index\.php$"  />
                    <action type="Rewrite" url="/en/"  /> <!--modified remove '/'-->
                </rule>
                <rule name="rule 2m" stopProcessing="true">
                    <match url="^index_cz\.php$"  />
                    <action type="Rewrite" url="/cz/"  /> <!--modified remove '/'-->
                </rule>
                <rule name="rule 3m" stopProcessing="true">
                    <match url="^/en/?$"  ignoreCase="true" />
                    <action type="Rewrite" url="/index.php"  />
                </rule>
                <rule name="rule 4m" stopProcessing="true">
                    <match url="^/cz/?$"  ignoreCase="true" /> <!--modified add '/'-->
                    <action type="Rewrite" url="/index_cz.php"  />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

When I visit the URL like http://{web_site_name}.azurewebsites.net/index_cz.php?a=a&b=b, it returns on site:

response in cz folder array(2) { ["a"]=> string(1) "a" ["b"]=> string(1) "b" }

Any concern, please feel free to let me know.

Upvotes: 0

Joe Raio
Joe Raio

Reputation: 1805

You would need to create a web.config with your rewrite rules in the proper section.

I generated the following from http://htaccesstowebconfig.com/

<rule name="rule 1m" stopProcessing="true">
    <match url="^index\.php$"  />
    <action type="Rewrite" url="//en/"  />
</rule>
<rule name="rule 2m" stopProcessing="true">
    <match url="^index_cz\.php$"  />
    <action type="Rewrite" url="//cz/"  />
</rule>
<rule name="rule 3m" stopProcessing="true">
    <match url="^/en/?$"  ignoreCase="true" />
    <action type="Rewrite" url="/index.php"  />
</rule>
<rule name="rule 4m" stopProcessing="true">
    <match url="^cz/?$"  ignoreCase="true" />
    <action type="Rewrite" url="/index_cz.php"  />
</rule>

The entire web.config file would look similar to this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rule 1m" stopProcessing="true">
                    <match url="^index\.php$"  />
                    <action type="Rewrite" url="//en/"  />
                </rule>
                <rule name="rule 2m" stopProcessing="true">
                    <match url="^index_cz\.php$"  />
                    <action type="Rewrite" url="//cz/"  />
                </rule>
                <rule name="rule 3m" stopProcessing="true">
                    <match url="^/en/?$"  ignoreCase="true" />
                    <action type="Rewrite" url="/index.php"  />
                </rule>
                <rule name="rule 4m" stopProcessing="true">
                    <match url="^cz/?$"  ignoreCase="true" />
                    <action type="Rewrite" url="/index_cz.php"  />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Upvotes: 0

Related Questions