Merdok Posted April 12, 2010 Share Posted April 12, 2010 Hi Guys, I've set up a shortURL system for my site so that http://dfmag.me/s/4x73 will return http://digitalfusionmagazine.com/modules/blog/article.php?cat=software&article=adobe-cs5-launch-the-creative-suite-feature-run-down This is great and I am happy with it but the long version of this rewritten url is http://www.digitalfusionmag.com/blog/software/adobe-cs5-launch-the-creative-suite-feature-run-down I would prefer the short url to redirect to this url instead of overwriting it. so that when the user types the short url in, the long url is displayed in the address bar. I'm not quite sure how to go about this, any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/198314-rewrite-the-short-url-back-into-the-long-one/ Share on other sites More sharing options...
cags Posted April 12, 2010 Share Posted April 12, 2010 It is uncommon to see this sort of forwarding since the rewritten url is what is called the 'pretty URL' and is what is generally considered to be the easier for a person to remember. The 'pretty URL' will generally point to the 'short' version which means if you redirect the short version to the 'pretty' version you get looping issues. If you wish to do it you will probably need a combination of RewriteCond's to check the QUERY_STRING (the query_string is everything after the question mark) and the L flag to make it the last rule used to prevent looping. I'm not entirely sure how you would go about matching multiple optional 'GET' attributes that can appear in any order or even if it's possible. One 'hack' that I would possibly try is to have a rewritten GET attribute. On article.php you check isset($_GET['rewritten']), if it is not set then you use the header function to redirect to the 'pretty URL' (the longer version). Then in your .htaccess file you rewrite back to the page, but always append rewritten=1 to the end of the URL. If the isset returns true, then you know that the user should be looking at the 'pretty URL' (unless some jackass happened to write rewritten=1 in the URL). It's late, I'm tired, I hope that makes some sort of sense. Quote Link to comment https://forums.phpfreaks.com/topic/198314-rewrite-the-short-url-back-into-the-long-one/#findComment-1040611 Share on other sites More sharing options...
Merdok Posted April 14, 2010 Author Share Posted April 14, 2010 Of course! That makes total sense. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/198314-rewrite-the-short-url-back-into-the-long-one/#findComment-1041535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.