Skip to content Skip to navigation

Removing cgi-bin from your URL

Posted by: 
Topics: 

Updated and Reviewed on 2012-05-03

Web applications like Drupal only run within the cgi-bin directory of your AFS space, but URLs such as www.stanford.edu/dept/foo/cgi-bin/drupal are ugly, hard to read and take longer to type.

The recommended solution is to use a vanity URL or virtual host such as foo.stanford.edu which can be requested from https://tools.stanford.edu and will effectively hide the full URL.

If for some reason you don't want to do that and would prefer to have your URL start with www.stanford.edu (as in www.stanford.edu/dept/foo), read on.

.htaccess tweaks

When people request www.stanford.edu/dept/foo, the web server reads the content as found in /afs/ir/dept/foo/WWW. The instructions below tell the web server to send all those requests, transparently, to the cgi-bin directory, in /afs/ir/dept/foo/cgi-bin/drupal instead.

Create an .htaccess file in /afs/ir/group-or-dept/your-group-dept-name/WWW, and enter the following lines:

RewriteEngine On
RewriteBase /group-or-dept/your-group-dept-name/
RewriteRule ^/?(.*)$ cgi-bin/your-drupal-directory/$1

In the example above, using /dept/foo and /dept/foo/cgi-bin/drupal the .htaccess in WWW would read:

RewriteEngine On
RewriteBase /dept/foo/
RewriteRule ^/?(.*)$ cgi-bin/drupal/$1

$base_url

Edit the sites/default/settings.php file and set the $base_url to the URL without the /cgi-bin/ portion. In the example above, the line would read:

$base_url = 'http://www.stanford.edu/group/foo'; // NO trailing slash!