Forum Moderators: phranque

Message Too Old, No Replies

Redirect link hell . PLEASE HELP!

change the link users see in address bar

         

dryice

10:50 am on Nov 11, 2009 (gmt 0)

10+ Year Member



Hi,

Was woundering if I could get a pointer from one of you .htaccess heroes?

Here goes:

I initiall wanted to create quick access to member profiles, so by typing:
"www.#*$!XX.com/members/MEMBERUSERNAME" it would redirect to "www.#*$!XX.com/SEARCHRESULTS?MEMBERUSERID=..."

As you can see, the problem I had mas I would be getting the USERNAME and so I could not on the fly redirect the person to a page (since I needed the USERID). What I did was use an intermediary php script that uses the USERNAME to query the database and find the USERID. then displays the page
"www.#*$!XX.com/SEARCHRESULTS?MEMBERUSERID=..."

I set up a rewrite rule as follows: -
---
RewriteRule ^members/(.*)$ membersredirectscript.php?un=$1 [NC,L]
---

So as an example, a user types in "www.#*$!XX.com/members/RICARDO". My htaccess then redirects internally to my membersredirectscript.php script. This script has a function which uses the username RICARDO to find that users USERID = 12, then it loads finally "www.#*$!XX.com/SEARCHRESULTS?MEMBERUSERID=12". The problem is that I still want the user to see in the address bar what he wrote - "www.#*$!XX.com/members/RICARDO"

All works 100% but the problem I get now is that the address/link users see is "www.#*$!XX.com/SEARCHRESULTS?MEMBERUSERID=..." and I would like them to see "www.#*$!XX.com/members/MEMBERUSERNAME"

Any ideas or clues?

Thanks!

jdMorgan

12:24 pm on Nov 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have access to the server configuration files, or could you ask someone to add something for you?

This is a good application for a RewriteMap, where your memberID lookup script could be called from the URL-to-filename translation phase of the Apache API to return the memberuserid before any content is served when a /members/<membersusername> - format URL-path is requested by aq client.

If not, then the solution lies outside mod_rewrite/.htaccess; Instead of having your script *redirect* to /searchresults?memberuserid=ricardo, this script should #include that searchresults script, so that a redirect response is never sent to the client (browser or robot). It is the client's response to this redirect that "changes the address bar."

Alternately, you could modify "searchresults" so that it would accept requests with "/members/<membersusername> in PATH_INFO, and do the translation itself before outputting any page content.

Jim

dryice

12:01 pm on Nov 12, 2009 (gmt 0)

10+ Year Member



Thanks a lot for your reply Jim, I really appreciate it!

I do have access to most of the server config files (are you refering to php.ini?)

Your idea of a rewritemap sounds intriguing, I'm going to read up on that a bit more.

Again thanks for helping out!