0

I am migrating a little PHP-Application to an Microsoft Azure WebApp.

I know that there are a lot similiar questions on stackoverflow but i can't figure it out on my own.

Previous i had this .htaccess file in one subdirectorie:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
</IfModule>

I now have this web.config file, i generated it with an online tool and modified it a little bit.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="rule 1J" stopProcessing="true">
                <match url="(.*)"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php?rquest={R:1}"  appendQueryString="true" />
            </rule>
            <rule name="rule 2J" stopProcessing="true">
                <match url="(.*)"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php"  appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Now i dont get an 404 error when trying to access the page. Seems like the web.config is not working at all.

Could please someone tell me whats wrong with my file?

Will Shao - MSFT
  • 1,189
  • 7
  • 14
schw4ndi
  • 231
  • 4
  • 18

1 Answers1

1

There is a little mistake of regular expression.

This is my test project directory:

enter image description here

And here is my test web.config:

<?xml version="1.0"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="rule 1J" stopProcessing="true">
                <match url="^(.*)$"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php?request={R:1}"  appendQueryString="true" />
            </rule>
            <rule name="rule 2J" stopProcessing="true">
                <match url="^(.*)$"  ignoreCase="true" />
                <action type="Rewrite" url="/api.php"  appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>

The result is that when visiting <web_app_name>.azurewebsites.net , it matches the 2nd rule and rewrite to <web_app_name>.azurewebsites.net/api.php .

And when visiting <web_app_name>.azurewebsites.net/example , it matches the 1st rule and rewrite to <web_app_name>.azurewebsites.net/app.php?request=example

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Thanks for your help! Now i get an 404 error all the time. Can you confirm that i translated the web.config file correct? – schw4ndi Oct 09 '15 at 09:23
  • Can you directly visit the `api.php` ? – Gary Liu Oct 09 '15 at 09:46
  • No i can not acces it directly. I get an internal server error. Details here: http://postimg.org/image/z9k06z3q7/. My project structure looks like this: http://postimg.org/image/rguv4uxr3/. Seems like i do not have permission to access the file. – schw4ndi Oct 09 '15 at 10:07
  • I allready tried to change the permission over the console with attrib to 'S R'. – schw4ndi Oct 09 '15 at 10:50
  • Is there any other technic i can try to make it accessible? Thanks. – schw4ndi Oct 09 '15 at 11:17
  • About your internal server error, per my experience, if there are some dependences which are not packaged in your project before deployed on Azure, it may occur this issue. Here is a similar thread http://stackoverflow.com/questions/32708809/laravel-5-1-on-windows-azure-web-application/32715542#32715542. And if it is a php error, we can set `display_errors` to `on` in php runtime, we can see in https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-change-the-built-in-php-configurations – Gary Liu Oct 09 '15 at 12:41
  • In my opinion, after fixing the internal server error, it will be easier to handle with the rewrite issue – Gary Liu Oct 09 '15 at 12:42
  • thanks for the help! It works now! After setting display_errors to on i noticed a view errors in my relativ paths! i am so happy now! :)))) – schw4ndi Oct 09 '15 at 22:32