How to convert a .htaccess file for use in your Web.Config file on Windows Server

 If you're running a Windows Server and you have to run PHP websites on it chances are that you will be asked to apply rules from a .htaccess file to one of the websites on your server. Windows Server does not use .htaccess files. These usually come from Apache servers. However, Windows Servers use a similar file called the Web.Config file located at the root of all your websites hosted on your Windows Server.

You'll be glad to know that there is a converter built into IIS 7 that will convert any .htaccess rules into the format required for the Web.Config file. To convert your .htaccess file simply follow these instructions:

  1. Log onto your server and open IIS.
  2. Double click on the 'URL Rewrite' icon from the list under 'IIS'.
  3. Click on 'Import Rules...' from the right side bar.
  4. Copy the htaccess contents supplied to you and paste them into the 'Rewrite Rules' text box. Once pasted you should notice the 'Converted Rules' area will update. If you click on the XML tab you will see the Web.Config format of the rule entered.
  5. Ensure you're looking at the Tree tab and right click on the 'rule name' tag in the Tree View and click on 'Rename' to rename the rule to something other than 'Imported Rule 1' so it will make more sense to anyone looking at the web.config file later on.
  6. Click on 'Apply' from the right side bar and your rule will be added to your web.config file.

That's it. You're all done! Nice and easy.

How to create a symlink or symbolic link on Windows Server 2008 to help share folders

A symlink or symbolic link can be easily created in Widows Server 2008 to share a common folders or files amongst projects. Lets assume you have a folder in domain1.com called CSS and you want to share this folder with domain2.com. You could just upload the CSS folder into domain2.com but then you need to FTP and update the CSS folder in 2 places. If both sites are using the exact same CSS this could cause you issues over time as you might forget to roll out updates from one site to another.

Using Windows Server 2008 you could create a symlink to solve this issue. Once you have the CSS folder created on domain1.com then you can run the following command from the command line on the server to create a symlink:

MKLINK /D C:\inetpub\wwwroot\domain2.com\CSS C:\inetpub\wwwroot\domain1.com\CSS

The format of the above is: MKLINK [new directory] [where to generate the new folder] [target folder you want the new link to go to]

If you're using Windows Server 2003 you can achieve something similar using:

fsutil hardlink create c:\foo.txt c:\bar.txt

There is a good answer on serverfault.com that covers this topic quite well - http://serverfault.com/questions/7109/how-do-i-create-a-symbolic-link-in-windows

How to install PHPMyAdmin on Windows Server 2008

At present if you install Wordpress as part of the Web Platform Installer it does not install PHPMyAdmin for you. Luckily this install is very easy to do.

Head over to http://www.phpmyadmin.net and download the latest installer to your server.

Once downloaded unzip the contents of the file and rename the folder to 'phpmyadmin'.

Copy this folder to your website containing Wordpress or php.

Open the file config.sample.inc.php into wordpad (notepad puts it all on one line) and enter in a new Blowfish_secret. It can be anything random like a password.

Next uncomment:

// $cfg['Servers'][$i]['controluser'] = 'pma';

// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

and replace with the root database username and password or create a new mySQL user called pma and use those details here.

Now uncomment the Storage database and tables - just remove the leading // from each line.

Save and close the config file. Rename it to: 'config.inc.php'.

Copy the phpmyadmin folder and paste it into your website root level.

Go to the Examples folder and open the create_tables.sql file using notepad. Copy all the content in here.

Open your website in a browser and point to yourdomain.com/phpmyadmin

Login using your root database and password. Ignore all the error messages for the moment. Go to SQL and paste in the sql text you copied. Now click on Go.

Log out of phpmyadmin and log in using the database username and password you used when setting up your Wordpress/MySQL database for this project.

Everything should now be working as expected for you.