Symlinks, Apache, and Windows

One of the main advantages that Linux holds over Windows is, in my opinion, symlinks and that they just work.  Whatever process you want to follow them, simply does because they’re implemented at such a deep level of the OS.

On Windows, on the other hand, default symbolic links (the ones you create by right-clicking in Windows Explorer) are implemented as what always seemed to be a hack (they’re files with their own .lnk extension!)  So processes like Apache can’t follow them transparently.  If you want to set up a file structure where certain paths under your DocumentRoot point to other paths, you’ll have problems.  Some people have suggested using Aliases but I don’t think they apply if you want to have path mappings like this:

C:\path\to\documentroot\dir1\
C:\path\to\documentroot\dir1\dir2\ -> C:\some\other\path

Which can easily happen if you’re mixing various projects which, for source control reasons perhaps, need to live in different places.

What I’ve found does work (at least on Windows 7), is using mklink.exe to create them:

Open a DOS prompt as an Administrator and execute this:

C:\>cd C:\path\to\documentroot\dir1
 
C:\path\to\documentroot\dir1>mklink /D dir2 C:\some\other\path
symbolic link created for dir2 <<===>> C:\some\other\path

Now somehow this variation of symbolic link to “dir2”  is actually followable by Apache – for all intents and purposes it seems to behave like a Linux symlink does.  Hopefully Windows 8 will make this less clunky – fingers crossed.

Leave a comment

Your email address will not be published. Required fields are marked *