다음을 통해 공유


Apache .htacces and .htpasswd equivalent on IIS for Azure Web Apps


Introduction

Since we already have Azure Web Apps on Linux (currently in Preview Mode), but already a lot of people are familiar with running their PHP and Java Apps on Windows Web Apps based on IIS.

Start Convert/migrate the app from Apache to IIS

Accordingly, there are 2 parts that you need to take care of when you are converting/migrating your application from Apache to IIS

1).htaccess equivalent on IIS web.config
2).htpasswd (if it exists) equivalent on IIS

So just to reassure you, you can make them and everything will work fine, and we will go through this together ;)

1).htaccess equivalent on IIS web.config

First of all you need to get your old .htaccess file (which is the same as web.config file but for Apache web servers) and have a look at it, it would probably look similar to that one
[htaccess screenshot] 

So to make it to web.config, currently most people tend to use a general web.config and configure it until it works (yes believe me :)) so the best, simplest and most effiecent way to do this conversion is as following

1) Download the IIS Manager for Remote Administration Extension

https://www.iis.net/downloads/microsoft/iis-manager 
This basically will let you use your local IIS Manager to connect to your Azure Website IIS and do any relate configuraiton there enjoying the flexibility and easy use of the IIS Manager UI interface

2) Open IIS Manager

From any PC, since we will connect to our Azure website remotely in all cases

3) Connect to your Azure Webstie

  • Select File -> Connect to Site
  •  
  • In your Site URL, type the Kudu Console URL, which is basically adding "scm" between your site name, and the azure domain as shown in the image below, and in the site name, type your web app name
  • For the Credentials, download the Publish profile from your Azure Portal to get the FTP User and Password
  • Now you give the connection a name, and you can see your website the left tree view

4) Select your Website in the left tree View
5) Select "URL REWRITE"
6) Import your .htaccess file
7 )Automatically the Mod-reqrite rules are converted to rewrite rules in web.config
8) Select the XML View
9) Copy this text and paste it in your web.config within the <> tag to do update the web.config manually

Thats it, now you translated your Apache .htaccess to IIS web.config equivalent without having to guess it :)

2).htpasswd (if it exists) equivalent on IIS

This part usually exist at the .htaccess like this:

it means that ceratin directories are password protected to disable access to them except by specific users, which comes in handy for many people.
However, in IIS the .htaccess file is completely ignored, therefore the .htpasswd file is not used
So we have to do this a bit differently in IIS by the following
Download IIS remote Manager, which enables you to remotely connect to Azure Web Apps
Open the IIS Manager
Connect to the Azure Web App site
Type in the URL and Crednetials
Go to the required folder/subfolder you want to manage its access
Select Authentication, and type in the username and password

Please drop a comment to let me know if this works for you or you have other cool ideas to share.