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

drubarth
drubarth used Ask the Experts™
on
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!  

Darryl
Comment
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.

Author

Commented:
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?

Thanks!

dr
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:

[InternetShortcut]
URL=http://www.google.com/
Modified=C0C6D3671C52C301F2

------------------------------------------

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
    </Directory>

     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.
------------------------------------------

#!/usr/bin/perl

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

use strict;

## make the filepath from the env vars
my $file_path = $ENV{DOCUMENT_ROOT}.$ENV{REQUEST_URI};
my $url;
my $text;

open(URL_FILE, $file_path);

## loop through the file to see if we can find a URL=$1
while(<URL_FILE>)
{
      $text .= $_;

      chomp($_);

      if($_=~/^URL=(.*)$/)
      {
            $url = $1;
      }
}

close(URL_FILE);

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

      print $text;
}

exit;
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