Jump to content

Recommended Posts

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.