View Full Version : Mod rewrite username forwarder
I would like to have a hack that allows users to view other users profiles by typing http://www.mydomain.com/username which forwards to member.php?u=23 or whatever. ive been told you can do this with mod rewrite, any1 care to have a go
Natch
11-04-2004, 12:32 AM
One way for a basic mod_rewrite of the members section: in your .htaccess, you need the following
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^member([0-9]+).html$ member.php?u=$1 [L]
Now to have it based on the membername, you would need to do a little on-the-fly manipulation of that .htaccess file: this is dangerous, as a bug in your .htaccess can make your site unviewable...
This said, it is doable to have a cached htaccess that is updated via a daily cron job based on the userlist, but it would make for high server overhead having a N-line htaccess file where N in the number of members you have...
memobug
11-04-2004, 05:55 AM
...Now to have it based on the membername, you would need to do a little on-the-fly manipulation of that .htaccess file: this is dangerous, as a bug in your .htaccess can make your site unviewable...
This said, it is doable to have a cached htaccess that is updated via a daily cron job based on the userlist, but it would make for high server overhead having a N-line htaccess file where N in the number of members you have...Maybe a simpler way would be to use mod_rewrite as described above, but instead of the cron cached stuff, instead call the existing membersearch using the member name as an argument like this:
https://vborg.vbsupport.ru/memberlist.php?do=getall&ausername=Natch
which will give you names like Natch. If you want names exactly matching Natch, you'd just need to hack memberlist.php slightly:
above
if ($ausername)
{
$condition .= " AND username LIKE '%" . addslashes_like(htmlspecialchars_uni($ausername)) . "%' ";
}
add
if ($myusername)
{
$condition .= " AND username = '" . "htmlspecialchars_uni($myusername)" . "' ";
}
and then change the link above to use myusername=Natch instead of ausername=Natch (UNTESTED)
Also: You've probably noticed that in the admin panel if you do a user search and there is only one result it goes right to that user. It shouldn't be too hard to get that to happen in memberlist.php too.
Regards,
Matt
Natch
11-04-2004, 11:29 PM
I had a chat with a mod_rewrite expert last night at my local PHP User Group meeting: suggestion from there was to write a small redirect script (uanmeparse.php) to parse the username to userid, then redirect to forumhome/member.php?u=$userid, and then mod_rewrite like so:RewriteEngine on
Options +FollowSymLinks
RewriteRule ^~([a-z0-9]*)$ unameparse.php?un=$1 [L,NC]Then, your unameparse.php goes in serverroot, along with .htaccess, and you call http://www.yourdomain.com/~username =>> this would redirect to the user's profile...
Natch
11-04-2004, 11:32 PM
Maybe a simpler way would be to use mod_rewrite as described above, but instead of the cron cached stuff, instead call the existing membersearch using the member name as an argument like this:
https://vborg.vbsupport.ru/memberlist.php?do=getall&ausername=Natch
which will give you names like Natch. If you want names exactly matching Natch, you'd just need to hack memberlist.php slightly:
above
if ($ausername)
{
$condition .= " AND username LIKE '%" . addslashes_like(htmlspecialchars_uni($ausername)) . "%' ";
}
add
if ($myusername)
{
$condition .= " AND username = '" . "htmlspecialchars_uni($myusername)" . "' ";
}
and then change the link above to use myusername=Natch instead of ausername=Natch (UNTESTED)
Also: You've probably noticed that in the admin panel if you do a user search and there is only one result it goes right to that user. It shouldn't be too hard to get that to happen in memberlist.php too.
Regards,
Matt
I do like your idea Matt: nice lateral thinking :D ... this other method creates a new file, instead of modding a vB file: sometimes a hack-less method is preferable...
Zachery
11-05-2004, 12:03 AM
I do like your idea Matt: nice lateral thinking :D ... this other method creates a new file, instead of modding a vB file: sometimes a hack-less method is preferable...
Why not use a 404 redirect in a new folder?
Natch
11-05-2004, 12:05 AM
Seems sloppy to me Zachery: a 404 used for something other than an actually missing page is against the HTML spec, and some proxy servers will simply serve up an ISP specific custom 404 page, rather than follow the script's directive, on getting the 404 HTML header.
memobug
11-05-2004, 05:44 AM
sometimes a hack-less method is preferable...
You're on the wrong forum then ;)
Regards,
Matt
Natch
11-07-2004, 12:08 PM
Not for long... ;)
Logikos
11-07-2004, 03:00 PM
This works, https://vborg.vbsupport.ru/member.php?username=Live%20Wire
Natch
11-08-2004, 10:27 PM
Well then, the .htaccess would be RewriteEngine on
Options +FollowSymLinks
RewriteRule ^~([a-z0-9\ -=]*)$ forumroot/member.php?username=$1 [L,NC]EG: I have this installed and working on mobileforces.org, with the following RewriteRule, to get http://www.mobileforces.org/~Natcher00 pointing to my Profile.RewriteRule ^~([a-z0-9\ -=]*)$ /forums/member.php?username=$1 [L,NC]NOTE: Spaces issue resolved:, also added characters used by my members, but you will need to update this list if you find characters your members use...
nr404
11-09-2004, 02:15 PM
just a small question considering my usual username (#404)
does this mods also work with usernames beginning with an #?
or is there maybe a possibility to use links like http://username.test.com
Borgs8472
11-09-2004, 08:56 PM
I'm interested in this hack, which of those options would people recommend most?
Natch
11-10-2004, 02:02 AM
With other characters, you will need to test adding those characters into the regular expression test (bolded)... I've added your # symbol as an example...RewriteEngine on
Options +FollowSymLinks
RewriteRule ^~([a-z0-9\ -=#]*)$ forumroot/member.php?username=$1 [L,NC]and if you get a 500 Internal server error, you might find you need to escape the character you want to add... (eg look at the way the space character is escaped with the "\" beforehand)...
Only trouble would be the who's online location. Say you go to Vvew ~M1th profile, you'd possibly get Unknown Location /~M1th
Natch
11-11-2004, 12:53 AM
Yeah: that could be resolved in the same way we resolved the issues of thread locations and mod_rewriting the forum/thread/post URL's (discussion on dani-web linked in my sig)...
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.