setting up htaccess redirects to wordpress post id

I'm trying to set up an automated link shortener using htaccess, in which, for example:

shorturl.com/u/123

.. will redirect to:

longurl.com/?p=123

Here's how I set it up; it's not working:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^shorturl.com/u?$ [nc]
rewriterule ^(.*)$ http://longurl.com/?p=$1 [r=301,nc]

Do I need to use QUERY_STRING or something? Can someone straighten me out?

Thanks,

Nathan
nbierm65Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

subscriptCommented:
When you say shorturl.com and longurl.com in the paths -- are these two different domains or... just a longer and shorter version of the same one?

Either way, this command should work for you, replace yours with this:

RewriteEngine On
RewriteBase /
RewriteRule ^u/([0-9]+)/? http://www.longurl.com/?id=$1 [L]

Does that work for you?

FYI
If permanently forwarding traffic to a new domain -- a 301 redirect is more search engine friendly.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nbierm65Author Commented:
didn't work. They're two different domains. The second uses WordPress, which uses ?p=ID instead of ?id=ID -- don't know if that makes a difference..
0
subscriptCommented:
Oops, my mistake -- yes:   Change it to p= instead.

Does it work then?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

nbierm65Author Commented:
no, still doesn't :(  The WordPress codex has this line of code for rewriting long urls; is this something I should look at:

 RewriteRule ^post/([0-9]+)?/?([0-9]+)?/?$ /index.php?p=$1&page=$2 [QSA]
0
subscriptCommented:
Huh, I guess I'm not sure I understand clearly what's happening.

So... does the redirect script work as written?

In other words -- if you visit the "shorturl.com/u/123" does it attempt to load the longurl.com address you gave it?

Or is the problem that the URL you're redirecting to doesn't work?

If you want to test to be sure -- send it to http://www.yahoo.com/?p=$1 instead.

At that point -- at least you know that the redirect script is working correctly. Then you just have to focus on finding the right URL structure to send to on the longurl.com domain... right?

Or am I missing something?
Let me know.



0
nbierm65Author Commented:
OK, I got my original attempt to work by removing the path to the subdirectory and installing the htaccess file directly in the subdirectory:


Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^shorturl.com?$ [nc]
rewriterule ^(.*)$ http://www.longurl.com/?p=$1 [r=301,nc]

Open in new window

0
nbierm65Author Commented:
partial solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.