Miomir Dancevic
Miomir Dancevic

Reputation: 6852

Url rewrite Azure PHP?

I have created some PHP app on Azure but this is my first time i am using IIS for my PHP application. I know how to use .htaccess for url rewrite on Apache and there is no problem. But how to accomplish that on Azure IIS. Here is my .htaccess for Apache.

.htaccess

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

Upvotes: 2

Views: 1441

Answers (2)

Miomir Dancevic
Miomir Dancevic

Reputation: 6852

Proper web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="false" />
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="Default.aspx" />
            </files>     
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="ModX IIS7 Rule 1 (By Simon Fraser)" stopProcessing="true">
                    <match url=".*" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_USER_AGENT}" pattern="^.*internal\ dummy\ connection.*$" />
                    </conditions>
                    <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
                </rule>
                <rule name="ModX IIS7 Rule 2 (By Simon Fraser)" stopProcessing="true">
                    <match url="^(manager|assets)" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="ModX IIS7 Rule 3 (By Simon Fraser)" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Upvotes: 1

Joe
Joe

Reputation: 4897

You need to use your Web.config file and use the <system.webServer> and <rewrite> rules within this.

You will need to use the following inside your web.config to replicate the code you have above from your .htaccess:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Main Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Upvotes: 2

Related Questions