Short URL service in the same directory as WordPress?
June 15, 2011 2:27 PM Subscribe
How do I create a custom bit.ly-like short URL service in the same directory as a WordPress installation?
I have an existing WordPress 3.0 installation for my blog. The current URL structure for individual posts is something like this: http://example.com/2011/post-title-goes-here
I would like to keep this current structure, but also use my domain (without subdirectories or subdomains) as a bit.ly-like "short" URL service where I can shorten not only my own content, but links to other content as well.
So, for example, the URL I posted above would work, but I want something like this to work as well: http://example.com/OC469ei
Right now I have a YOURLS installation in a subdirectory that works, so my links are something like this: http://example.com/s/OC469ei
But I would really like to do away with the subdomain if at all possible. YOURLS claims specifically that it cannot be installed in the same directory as WordPress because they both need .htaccess files.
I'm happy to use whatever method necessary to make this work, even if it's a manual process that's not as pretty as the YOURLS admin interface.
Please let me know if there's anything I need to clarify.
I have an existing WordPress 3.0 installation for my blog. The current URL structure for individual posts is something like this: http://example.com/2011/post-title-goes-here
I would like to keep this current structure, but also use my domain (without subdirectories or subdomains) as a bit.ly-like "short" URL service where I can shorten not only my own content, but links to other content as well.
So, for example, the URL I posted above would work, but I want something like this to work as well: http://example.com/OC469ei
Right now I have a YOURLS installation in a subdirectory that works, so my links are something like this: http://example.com/s/OC469ei
But I would really like to do away with the subdomain if at all possible. YOURLS claims specifically that it cannot be installed in the same directory as WordPress because they both need .htaccess files.
I'm happy to use whatever method necessary to make this work, even if it's a manual process that's not as pretty as the YOURLS admin interface.
Please let me know if there's anything I need to clarify.
Rhomboid is dead on. Mod-rewrite may frustrate you a bit, but it's the best solution for this.
posted by bprater at 3:02 PM on June 15, 2011
posted by bprater at 3:02 PM on June 15, 2011
I cheat this a little bit by putting all my content at www.example.com, and having my URL shortener at example.com. In that example.com's VirtualHost section,
Thus http://example.com/A_Valid_Document redirects to http://www.example.com/A_Valid_Document, and http://example.com/ljsfa gets matched by tinylink.pl and redirected to the appropriate place.
posted by straw at 3:10 PM on June 15, 2011
<Location />...</Location>
I use RewriteEngine:
tinylink.pl checks to see if it's got the URL in its tied hash, and if it doesn't then it just redirects to http://www.example.com/$1RewriteEngine on
RewriteRule htdocs/$ http://www.example.com/
RewriteRule htdocs/(..*)$ http://www.example.com/cgi-bin/tinylink.pl?r=$1
Thus http://example.com/A_Valid_Document redirects to http://www.example.com/A_Valid_Document, and http://example.com/ljsfa gets matched by tinylink.pl and redirected to the appropriate place.
posted by straw at 3:10 PM on June 15, 2011
So a little more thinking... How about:
This would take anything in your main directory that consisted only of upper and lower case letters and numbers, and redirect it to your shortener. That way you can still have http://example.com/2011/... and http://example.com/page.html go where they should, but http://example.com/OC469ei will redirect to your shortener.
I'm not sure how to rewrite that RewriteRule to fit into the .htaccess rather than the Apache site config, but it shouldn't be too hard.
posted by straw at 4:42 PM on June 15, 2011
RewriteRule htdocs/([A-Za-z0-9]+)$ http://example.com/s/$1
This would take anything in your main directory that consisted only of upper and lower case letters and numbers, and redirect it to your shortener. That way you can still have http://example.com/2011/... and http://example.com/page.html go where they should, but http://example.com/OC469ei will redirect to your shortener.
I'm not sure how to rewrite that RewriteRule to fit into the .htaccess rather than the Apache site config, but it shouldn't be too hard.
posted by straw at 4:42 PM on June 15, 2011
This WordPress plugin may help (it appears to have been abandoned but it's worth a shot).
posted by cvp at 5:47 PM on June 15, 2011
posted by cvp at 5:47 PM on June 15, 2011
« Older Neurological Physical Therapist Recommendation!... | Describe once, upload everywhere? Newer »
This thread is closed to new comments.
posted by Rhomboid at 2:56 PM on June 15, 2011