Wednesday, April 7, 2010

Symlink - infinite folder issue

Hey All,

Recently I ended up in setting a Symlink for one of my sub-sites driven by Drupal. The url for my sub-site was somewhat like this "www.example.com/sub1". What I actually did was created a symlink at the root called sub1. The site worked fine and I never realized that even if a user types "www.example.com/sub1/sub1" the same homepage is served to the user by the server. It does not stop there, when I typed www.example.com/sub1/sub1/sub1 , the same happens..The same is true for infinite number of /sub1. That was totally insane. How could have I not thought about such an issue. Obviously it will work that way because the Symlink was pointing to the drupal root. So no matter how many /sub1 I type, the symlink will keep adding sub1 to the url and still point to the same homepage. Not that there are that many physical existence of sub1 folders, but as you know symlink is just a way to pretend as if the files physically exist.

Something had to be done there to avoid sinking into multiple/infinite folders of the same name sub1.

Solution:

Open the vhosts.d file (the configuration file for your site, note that this file's name might change depending on how your server is configured). Add the following < Directory /drupal/sub1/sub1/ > Order Deny,Allow Deny from all < /Directory >

Note that I have assumed that drupal is installed in the root. Actually this can work for any symlink issue (not necessarily to be used with drupal). All it does is asks the server not to serve a client's request or even a bot's request if they ask for www.example.com/sub1/sub1 . Note that by denying access to the second level folder designation, all other infinite folder access can be avoided (for example www.example.com/sub1/sub1/sub1/sub1/ can be denied as well).

Hope that helps!!!!

0 comments:

Post a Comment