It has to all be done within the PHP scripts on the site itself.
There's no way for
.htaccess to be able to know that a URL request for
/UB349 refers to the internal filepath
/folder305/folder18/filename38294.htm inside the server.
If we're talking only about the domain name itself -- say, "www.very-long-domain-name-here.com" and you want to redirect some short domain name like "short.com" to that, then there may be a big mistake here before coding even starts.
Either promote the long domain name and link only to it, or promote the short domain name and link only to that one. You can do things like publish the short domain name in print and on TV/radio where the assumption is that it will always have to be typed-in, and then redirect those requests to the proper "branded" domain, but don't link to or promote any domain on-line that is not your "branded money-domain."
This is an SEO issue, best discussed in one of our search engine forums, but the bottom line is that if you promote and link to both domains on-line, then you are essentially creating "extra competition" for your own site in the form of multiple URLs competing for links and for search engine rankings. Plus, search engines take a dim view of a company that cannot make up its mind what it wants to be called on-line -- One company, one domain is the general rule, unless you are really huge (like General Motors with GMC.com and Chevrolet.com, for example).
Invoking a redirect from short.com to exquisitely-long-and-sinuous.com for every request also wastes your visitors' time and makes a mess of your logs and stats, because every initial client request results in a server response saying, "Nope, sorry. No can do. That resource has moved, please ask for it again at this new URL... This HTTP connection is now closed, Good-bye. Please call again soon." The client must then open a second HTTP connection and re-request what it wanted in the first place, now using the new URL provided in the server's redirect response... Big waste of time and bandwidth, and your "server hit count" essentially doubles. Both client requests get logged, skewing your stats, and Google and the other search engines will think that your site is a technical mess. This would likely constitute a "negative signal of quality" in their eyes.
The use of the short url is required for Twitter. The short URLs will be tweeted and not used for other purposes but it's essential the longer main domain is used for general www & email, the short (not so user friendly as reader can't see much about file name or path) is just for tweeting.
Surely a lot of sites are already doing this?
Thank you for your comments.
Twitter doesn't require short URLs these days.
They will auto-shorten anything over 138 characters, however if your URLs are already quite long you'll want to shorten them to leave room for the rest of the message.
You'll need a script that looks in the database for the new URL when a short URL is requested, and then sends the HTTP 301 redirect header pointing to that new location.
The 140 character limit tweet will include both the short url and the tweeters comment (so needs to be extra short). Thanks for the comments.
I was just clarifying that "The use of the short url is required for Twitter." means that you are "using short URLs with Twitter" and not "Twitter requires short URLs".