Jump Start to Easy URLs
Category: Website Design and Development | Date: 2003-10-25 |
Youve probably seen those short and sweet URLs that "jump" or "go" somewhere. In my early days (last year) as a PHP coder, webmaster of a new PHP/mySQL-based site and e-zine editor, I noticed more and more of these jump urls. They got my attention because they seemed like an easy way to:
Reduce the length of especially long URLs[ENDBULLET]
"Hide" the identity of a link[ENDBULLET]
The former item was especially critical when I wanted to display a newsletter link to information that would be of great interest to my readers, but the length of the URL exceeded the standard 65-character limit of standard text newsletter lines. A URL that breaks into a second line of text is virtually useless to the reader -- its not clickable "as is", and it requires one or more copy-and-paste operations to get it into the browsers address line.
For example, I have a page thats deeply buried in my sites structure. Because of this, I want to replace its actual URL:
http://www.webthejoint.com/somedirectory/archivedirectory/2000 /december/index.html
with something like this:
http://www.webthejoint.com/jump.php?id=5
Luckily for me, I use PHP and mySQL. If you do, too, heres an easy solution that you can cobble together quickly.
Start by creating a simple mySQL table called "redirects". If your hosting service doesnt provide a front-end for mySQL table creation, execute an SQL statement like this:
CREATE TABLE redirects ( id mediumint(8) unsigned NOT NULL auto_increment, address varchar(200) NOT NULL, label varchar(60) NOT NULL, PRIMARY KEY (id), KEY id (id, address), UNIQUE id_2 (id));
Once the table has been created, add records to this table. The fully-qualified URL gets entered into the address column, a description (for documentation purposes) in the label column. No need to fill in the id column -- mySQL automatically assigns this number.
For the above link, my record would have the following column values:
address: http://www.webthejoint.com/somedirectory/archivedirectory/200 0/december/index.html
label: Archive list for Dec. 2000 newsletters
Assuming this was the fifth record I put into the table, the URL I would use would be the much simpler:
http://www.webthejoint.com/jump.php?id=5
As you may have guessed, the final piece of this puzzle is a PHP program called "jump".
Copy this code and save as "jump.php" into your root directory. Remove the line counters before use.
~~~~~~~~~~~ ( begin code ) ~~~~~~~~~~~1 ~~~~~~~~~~~ ( end code ) ~~~~~~~~~~~
Now our example link http://www.webthejoint.com/jump.php?id=5) takes the visitor to our "buried" page. The jump program does a lookup to the redirects table in mySQL and returns the record whose id value is "5". The program then sends the browser an HTTP "content has moved" notice, telling it that the page it is after is actually at the "buried" pages address. The browser, upon receiving this notice, transparently moves on to the longer address. Thats all there is to it!
Generally I use "straight" links on our site at WEBtheJOINT, but when I find the need to shorten a long URL or perhaps "disguise" the actual link, all I need to do is add a record to my redirects table and note the id number that mySQL has assigned to the record.
by Keith Reichley March, 2001
About the Author
Keith Reichley is webmaster for webthejoint.com, the web resource center for small business.
keith@webthejoint.com
http://www.webthejoint.com
Reduce the length of especially long URLs[ENDBULLET]
"Hide" the identity of a link[ENDBULLET]
The former item was especially critical when I wanted to display a newsletter link to information that would be of great interest to my readers, but the length of the URL exceeded the standard 65-character limit of standard text newsletter lines. A URL that breaks into a second line of text is virtually useless to the reader -- its not clickable "as is", and it requires one or more copy-and-paste operations to get it into the browsers address line.
For example, I have a page thats deeply buried in my sites structure. Because of this, I want to replace its actual URL:
http://www.webthejoint.com/somedirectory/archivedirectory/2000 /december/index.html
with something like this:
http://www.webthejoint.com/jump.php?id=5
Luckily for me, I use PHP and mySQL. If you do, too, heres an easy solution that you can cobble together quickly.
Start by creating a simple mySQL table called "redirects". If your hosting service doesnt provide a front-end for mySQL table creation, execute an SQL statement like this:
CREATE TABLE redirects ( id mediumint(8) unsigned NOT NULL auto_increment, address varchar(200) NOT NULL, label varchar(60) NOT NULL, PRIMARY KEY (id), KEY id (id, address), UNIQUE id_2 (id));
Once the table has been created, add records to this table. The fully-qualified URL gets entered into the address column, a description (for documentation purposes) in the label column. No need to fill in the id column -- mySQL automatically assigns this number.
For the above link, my record would have the following column values:
address: http://www.webthejoint.com/somedirectory/archivedirectory/200 0/december/index.html
label: Archive list for Dec. 2000 newsletters
Assuming this was the fifth record I put into the table, the URL I would use would be the much simpler:
http://www.webthejoint.com/jump.php?id=5
As you may have guessed, the final piece of this puzzle is a PHP program called "jump".
Copy this code and save as "jump.php" into your root directory. Remove the line counters before use.
~~~~~~~~~~~ ( begin code ) ~~~~~~~~~~~1 ~~~~~~~~~~~ ( end code ) ~~~~~~~~~~~
Now our example link http://www.webthejoint.com/jump.php?id=5) takes the visitor to our "buried" page. The jump program does a lookup to the redirects table in mySQL and returns the record whose id value is "5". The program then sends the browser an HTTP "content has moved" notice, telling it that the page it is after is actually at the "buried" pages address. The browser, upon receiving this notice, transparently moves on to the longer address. Thats all there is to it!
Generally I use "straight" links on our site at WEBtheJOINT, but when I find the need to shorten a long URL or perhaps "disguise" the actual link, all I need to do is add a record to my redirects table and note the id number that mySQL has assigned to the record.
by Keith Reichley March, 2001
About the Author
Keith Reichley is webmaster for webthejoint.com, the web resource center for small business.
keith@webthejoint.com
http://www.webthejoint.com
Copyright © 2005-2006 Powered by Custom PHP Programming