ProLinkz(TM) Does Short URLs
When you need a "short URL", in an email or ezine for example, ProLinkzTM will manage it nicely for you. And it will track the click-thrus, too.
Perhaps you have a long URL like this:
http://example.com/directory/directory2/directory3/
averylongfilenamethatwrapsbadlyinanemail.shtml?=
morestuffandstuff
Obviously, this is going to wrap badly in an email or ezine, causing confusion and frustration.
We can pop that Very Long URL into ProLinkzTM and get something like this:
http://example.com/cgi-bin/prolinkz/pl.cgi?code
But wait! We can make it even shorter with a little .htaccess editing. We can have a URL like this:
http://example.com/code
It's not difficult to do; included below are an .htaccess file generator and complete instructions.
Two things are required:
- ProLinkz needs to be installed on your server. (It is available here if you don't already have a copy.)
The .htaccess file needs to be edited.
(The .htaccess edit that we will do extracts the code from the URL and sends it to ProLinkz.)
ProLinkzTM
The ProLinkzTM software redirects the browser to the correct
destination URL and counts the occurrences.
To use the short URL method described here, set up a redirect code with the software's control panel.
When you are ready to create the short URL link, type the URL to your domain followed by a slash and the redirect code.
But before you publish the short URL link, you'll need to insert some lines into the .htaccess file.
The .htaccess File
Editing the .htaccess file is easy- just copy the generated lines and
paste, but there are several important notes in this article
that need to be understood. The instructions
are rather long because each line being pasted into the
.htaccess file is explained.
Seven or eight lines will need to be added to the .htaccess
file, the number of lines depending on whether or not you
have specified an error document handler in the file.
Use the generator below to generate the lines.
If you already have an .htaccess file in the document root
directory of your server, you can paste the new lines at
the end of the file.
If you do not have an .htaccess file, create one in the
document root directory.
(The document root directory is the directory where your
domain's index file is at, the file containing the web page
visitors see when they type only your domain name into
their browsers.)
Important note #1:
Some servers are configured so the .htaccess file does
not appear in FTP file listings.
Determine whether or not there is a .htaccess in the
document root directory before you create a new one
and overwrite what might already be there.
To determine whether or not a .htaccess file is in
the directory, try to download the file by manually
specifying .htaccess as the name of the file to
download. If the file is in the directory, the FTP
program should be able to find and download it.
The .htaccess edit will cause the server to use the Apache
module mod_rewrite to redirect URLs containing a ProLinkzTM
code to the ProLinkzTM link handling script.
Important note #2:
Some hosting companies configure their servers so their
clients can not use the Apache module mod_rewrite.
If yours is configured that way, attempting to use
the Apache module mod_rewrite causes an Internal Server
Error for any and all pages your visitors might try to
access!
Therefore, either find out from your hosting company
whether or not you can use Apache module mod_rewrite,
or test the server yourself.
To test the server, create a subdirectory in the
document root. Let's call it "test" for example.
Upload a .htaccess file into the "test" subdirectory
that contains this line:
RewriteEngine on
Also upload a file named index.html into the "test"
subdirectory. It doesn't matter what this index.html
file contains so long as it's plain text.
Now, use your browser to access that directory. Access
it by typing
http://example.com/test/
into the browser's address bar (replacing example.com
with your own domain name).
If you get an Internal Server Error (or an error page
indicating something is awry), then you won't be able
to implement the method described in this article with
that hosting account unless the hosting company
makes the Apache module mod_rewrite available.
If things seem normal, the index.html file loads into
the browser, then your account is able to use Apache
module mod_rewrite.
After the test, remove the files from the "test"
subdirectory, then remove the subdirectory itself.
Now that you know your hosting account can use Apache module
mod_rewrite, let's edit the .htaccess file for the document
root.
Load the .htaccess file into a plain text word processor
like NotePad or BBEdit.
Generate the lines with the generator and add them to the .htaccess file.
Here is a line-by-line explanation.
Line 1 turns the rewrite engine on. The rewrite engine is
in the Apache module mod_rewrite, which your hosting account
must be able to use. See "Important note #2", above.
Line 2 tells the rewrite engine that the base of URIs is
your document root.
Line 3 is a condition line, specifying that the URI must
not be blank, will never do the redirect if it is blank,
like it would be with URL http://example.com/ for example.
(If any condition lines fail, the redirect won't happen.)
Line 4 is another condition line, specifying that the URI
may not contain a "/" character after a letter or number.
This aborts the redirect for http://example.com/file/ URLs.
The [NC] at the end of the line tells the engine that no
case differentiation shall take place (an "A" to be
considered equal to an "a").
If you answered "Yes" to the question about whether or not your current .htaccess file
contains an error document line, then line 5
aborts the redirect if the URI
contains a period followed by a letter or
number (case-insensitive). For example,
http://example.com/page.html won't redirect.
(If you answered "No", then the generator will not have generated that line.)
The third line from the bottom is a condition line saying that the file name being
requested (which would be the code following the last "/"
in URL http://example.com/code) must not be the name of an
existing file.
The second line from the bottom is a condition line saying that the file name being
requested must not be the name of an existing directory.
If all of those condition lines pass, then the bottom line is
executed. This is where the redirect happens.
When the generated lines are pasted into the .htaccess file,
upload it and test it.
Important note #3:
Do not delay the testing!
When the .htaccess file is uploaded, the effect is
immediate.
If something is awry with the .htaccess file, your
site visitors may receive an Internal Server Error
or may be redirected to a page they shouldn't be
redirected to or may experience page redirects in
an infinite loop.
Just be prepared to delete the .htaccess file from
your server if something like that shows up in your
testing. Delete from the server, then review and
correct the copy you have on your computer. Once
corrected, re-upload and re-test.
Test a URL on your server:
-
To a page that exists.
-
To a page that doesn't exist.
-
With no page name (http://example.com/)
-
With a valid ProLinkzTM code, to determine that
the short URL works like it should.
-
To a web page in another directory (if you
have documents in other directories) that
exists, and to one that doesn't exist.
If those test okay, the modified .htaccess file is working.
More information about the Apache module mod_rewrite (which
is used in this "short URL" implementation) can be found at
the Apache Software Foundation. Two articles you may wish
to read are "Module mod_rewrite; URL Rewriting Engine" and
"URL Rewriting Guide"