Forum Moderators: phranque
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!
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