Page 1 of 1

Mod Rewrite quick help!

Posted: Fri Feb 20, 2004 9:34 am
by bumple
Hi all!

I made a user_template.php for displaying any user's information from a database, however, I have a few questions after reading the modrewrite FAQ and the Working with Forms Tutorial.

I want users to come to http://www.domain.com/username to be redirected to http://www.domain.com/user_template.php?user=username.

1) Since my modrewrite won't contain numbers (as it did on the short tutorial at http://codewalkers.com/faq/4/13.html) and just ID's, how would I do it? Would it be something like this in my .htaccess file?:

[quote]
RewriteEngine on
RewriteBase /
RewriteRule ^(<what goes here>+)/$ /user_template.php?user=$1
[/quote]



2) I do have access to my .htaccess file, but it already has a bit of stuff in it. One thing: my current .htaccess is in the /logs directory of my server. Can I make a new .htaccess for the root directory of my server (dont I have to do that?)?


Thanks a lot guys!
-BUMPle.

Posted: Fri Feb 20, 2004 10:37 am
by steve@oeic.net
([a-z]+[A-Z]+) might work, but I'm not great with regular expressions.

Posted: Fri Feb 20, 2004 11:17 pm
by bumple
that doesn't seem to be working...
-BUMPle.

Posted: Sat Feb 21, 2004 3:55 am
by bumple
BUMPity!
-BUMPle.

Posted: Sat Feb 21, 2004 9:42 am
by tylerdurden
I got it to work like this:

RewriteRule ^user_(.*)$ user_template.php?user=$1

it however requires you to prepend user_ to the actual username like so:

http://www.domain.com/user_username

or use this:

RewriteRule ^user/(.*)$ user_template.php?user=$1

and call it like

http://www.domain.com/user/username

Else I don't know, since you'd have to make sure you can still call normal pages (index.php) and subdirectories. Your regex would have to catch these.

Posted: Sat Feb 21, 2004 10:14 am
by bumple
I'm getting there...but take for example xanga's website.

If you type in:

http://www.xanga.com/ilovecats


it will automatically redirect you to:

http://www.xanga.com/home.aspx?user=ilovecats


How did they do that?

Thanks!
-BUMPle.

Posted: Sat Feb 21, 2004 10:42 am
by tylerdurden
Didn't say it wasn't possible;-)
I overlooked the obvious. Try this:

RewriteRule ^([a-zA-Z0-9_]*)$ user_template.php?user=$1