How to Make .URL Files be Links from a Web Server

drubarth used Ask the Experts™
I'd like to configure my Apache server so that .url files (internet shortcut files in MS Windows) when served go to the link they contain. I was originally thinking that perhaps I could configure a MIME type, but I haven't been able to get this to work. Fyi, all my users are on a Windows platform.

I'm a PHP programmer, but don't have much experience with configuring Apache.  Perhaps there's a way to write a PHP program that will intercede when a .URL file has been requested so I can read the file and do a redirect???

Any help would be greatly appreciated!  

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
if you don't get a response anytime soon, you may want to re-phrase the question.  maybe somebody else will understand what you mean, but i don't get what you're asking.


Sorry, let me try to clarify...  

In Internet Explorer you can drag a URL to a folder (Add to Favorites is the same). When you do this, it creates an Internet Shortcut file in Windows, usually with the extension of .URL.  If you open this file, it opens IE and goes to the web page address embedded. I would like to be able to upload these Internet Shortcut files directly to my web server and have them act as links when someone views a directory listing on the web server and clicks on the file name.

Does that help?


I'm not sure about doing this in PHP - and would say that mod_perl is the best
way to do that kind of file to URL translation.

However - intruiged, here is a simple perl script you can install, with accompanying
httpd config that should do the job.  The remaining question I can't answer is
why you want to do this in favour of a simple web-page but then its all good isn't it?

Also - the script assumes your server is UNIX (the browser dosn't matter),
although I'm sure it can be moved to windows.

If you have mod_perl installed let me know - otherwise you can probably craft
the same thing in PHP ?

Kind Regards


Format of a '.url' file:



Put this in the httpd.conf for the sites containing .url files:

    ScriptAlias /cgi-bin/ "/home/your_username/cgi-bin/"

    <Directory "/home/your_username/cgi-bin/">
        AllowOverride None
        Options ExecCGI
        Order allow,deny
        Allow from all

     ScriptAliasMatch ^/(.*\.url)$ /home/your_username/cgi-bin/url_redirect.cgi

Obviously you need to make sure this directory exists.
Put the script into it and make sure it is executable (chmod a+x url_redirect.cgi) etc

The ScriptAliasMatch line aliases anything.url onto the script that will then re-direct.


## This is url_redirect.cgi - put this in /home/username/cgi-bin (or similar)

use strict;

## make the filepath from the env vars
my $url;
my $text;

open(URL_FILE, $file_path);

## loop through the file to see if we can find a URL=$1
      $text .= $_;


            $url = $1;


## If we have found a URL, then redirect to it, otherwise print the contents of the file
      print "Location: $url\n\n";
      print "Content-type: text/plain\n\n";

      print $text;

you want to use "file upload" through html to upload these as "links" on a website?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial