Forum Moderators: phranque

Message Too Old, No Replies

To ~ or not to ~

find user on community site

         

AWysocki

9:38 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



My goal is the following

Leave these URL's alone:
[mysite.com...]
[mysite.com...]
[mysite.com...]
[mysite.com...]
[mysite.com...]

But if the user types in:
[mysite.com...]

to convert the username into a url like
[mysite.com...]

I am willing to change the addphoto profile to have a dot extension. To say what I want in english is:

any URL without an extension (.something) or a subdirectory to get mapped to the profile.php page?

I've used this Rewrite rule but would like to get rid of the ~
RewriteRule ^/~([^/]+)/?(.*) /profile.php?uid=$1 [R]
RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ [R]

Thanks
Andy

jdMorgan

11:04 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Andy,

Welcome to WebmasterWorld!

There are too many ambiguities here to present a solution, but a few example RewriteConds mays demonstrate a way forward:


# Suppress rewrite if "home page" request
RewriteCond %{REQUEST_URI} !^/?$
# Suppress rewrite if additional "/" or any "." in URL (excludes all subdirectories and .html, .php, .gif files, etc.)
RewriteCond %{REQUEST_URI} !^/.+(/¦\.)
# Forward usernames to script (usernames must be alphanumeric, undescore or hyphen only)
RewriteRule ^/([a-z0-9_\-]+)/?$ /profile.php?uid=$1 [NC,L]

This is a "silent" internal rewrite that will do what you want without exposing the fact that the server path has been changed. To do so would open you up to all sorts of "fishing for accounts" by curious users (and also look ugly).

The usernames have been restricted to a known reduced character set to prevent future naming conflicts and problems with php calling parameter syntax. For example, this prevents a user trying to sign up as "Best_B&B", which would cause php to think that there were two calling parameters, "Best_B" and "B" because "&" is used as a parameter separator. You should also enforce this same restriction in the "account creation" script.

Change the broken pipe "¦" character above to a solid pipe before use. Posting on this board modifies them.

I have no idea what your last rule is for, so I can't comment much on it. However, if its purpose is to "fix" broken incoming links, then you should use a canonical URL and a 301 redirect:


RewriteRule ^/([uge])/([^/]+)$ http://www.example.com/$1/$2/ [R=301,L]

Jim

AWysocki

8:53 pm on Aug 23, 2005 (gmt 0)

10+ Year Member



Jim,
Thanks for that help it gave me a lot to work with, and does what I want.

Because I currently have ~userid convention and % encode the weird characters. I've since stopped those characters for new accounts, but still have a few with % $ & in them. I tinkered with your Rule to the following.

RewriteRule ^/([^\n~]+)/?$ /profile.php?uid=$1 [NC,L]

The way I read this is that it will take any character with the exception of NewLine and ~ and pass it on. When I print the users URL for PHP I convert Spaces to + and & to %26 and so on.

So on their profile page they would see something like this

Direct Link:
[sitename.com...]

That rule seems to work on my test setup but not sure if I'm opening myself to other problems by doing it.

Again Thanks very much.
Andy