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

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
drubarthAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

philjones85Commented:
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.
drubarthAuthor 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
webkit_kaiCommented:
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;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
philjones85Commented:
you want to use "file upload" through html to upload these as "links" on a website?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.