views:

43

answers:

2

hello, i am trying to make short url or even pretty URLs inside my wordpress. suppose, i have a the_content filter that finds all external links inside post content, it needs to return short or pretty urls relative to my site URL.

external url:

stackoverflow.com/questions/ask

pretty url:

myblog.com/xyxd

making url is not a big deal! but I don't understand how can I then redirects visitors to original external site when he/she is visiting this pretty url?

suppose, one clicks or or enter:

myblog.com/xyxd

now, I need to redirect him (301/302) to:

stackoverflow.com/questions/ask

how can I do handle this (and also without conflicting with wordpress's native post/page urls).

any help?

thanks in advance even if you read this problem :).

Note: I had to remove http:// from all links as stackoverflow is not allowing me to put more than one link!

A: 

Check out WordPress pretty link.

UPDATE:

You could hook into wp_insert_post and scan the content for URLs using regex or a HTML parser.

Then use the Pretty Link API to insert pretty links for each URL.

TheDeadMedic
sir, i have already test that. that is for manual entries. I need to do it programatically! thanks for your input
HungryCoder
+1 for calling me sir ;)
TheDeadMedic
Thanks. once I thought I can use these functions! later thought no! but as they are suggesting it officially, i believe I can use it :). thanks again for link.
HungryCoder
A: 

You already have one by default

http://yourweb.local/blog/?p=2365

You can use post IDs as shorturl, something like default settings for permalink structure http://codex.wordpress.org/Using_Permalinks

So inside loop You can use:

<a href="<?php bloginfo('url');?>?p=<?php the_ID(); ?>" title="<?php the_title(); ?>"><?php bloginfo('url');?>?p=<?php the_ID(); ?></a>

(EDITED:or even better) but don't use: Because moving WP brog to another blog, will leave old blog's address

<a href="<?php the_guid(); ?>" title="<?php the_title(); ?>"><?php the_guid(); ?></a>
Umbrovskis.com