/    Sign up×
Community /Pin to ProfileBookmark

I have a site I am working on that wants to allow users to create their own page, having a url like [url]www.site.com/name[/url]. I have the registration form built and storing their data in a database, and the “name” part of the url would be their first and last name together. How would I allow url’s like this to be valid on my site?

Thanks!!

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@opifexSep 28.2009 — site.com/name already is valid.... it's just a folder in site.com
Copy linkTweet thisAlerts:
@jrthor2authorSep 28.2009 — I'm not following. I'm not creating a folder for everyone who registers.
Copy linkTweet thisAlerts:
@NogDogSep 28.2009 — You would probably use URL rewriting at the web server level (e.g. Apache mod_rewrite module), converting "http://example.com/foobar" to "http://exampe.com/userpage.php?user=foobar", then userpage.php would use $_GET['user'] to grab the applicable data from the database.
Copy linkTweet thisAlerts:
@jrthor2authorSep 28.2009 — Would I have to create a rewrite rule for everyone that registers an account?
Copy linkTweet thisAlerts:
@NogDogSep 28.2009 — Nope, just one that takes whatever is at the end and applies it to the URL query string value. I'm not real good with this stuff, but it might be something like:
<i>
</i>RewriteEngine on
RewriteRule ^([^/.]+)/?$ user.php?user=$1

This would match on "http://example.com/username" or "http://example.com/username/" and change it to "http://example.com/user.php?username" (if my code is correct), but note that it would not match if you allowed a "." in user names (in which case more thinking would need to go into this).
Copy linkTweet thisAlerts:
@jrthor2authorSep 28.2009 — so every page request would go through this rewrite rule, right? How would the rule know if what came after example.com/ is a username or not?
Copy linkTweet thisAlerts:
@NogDogSep 28.2009 — It would not "know", it would be up to you to ensure that your web page URL naming convention will facilitate this. In the example I provided, I'm assuming there will be no "." in the the user name, and that if there would be either no "/" or only a terminal "/". Therefore a URL like "http://example.com/index.php" or "http://example.com/directory/foo/bar" would not match; only something like "http://example.com/foo" or "http://example.com/bar/" would match.
Copy linkTweet thisAlerts:
@jrthor2authorSep 28.2009 — hmm, I will have urls like example.com/contact or example.com/admin, so I'm not sure that will work. Any other suggestions on how this could work? Maybe I should make all user pages have links like example.com/portal/username, then, the rule would look for /portal/username and redirect the user to the page. what would the rewrite rule look like if I wanted that? Would this be correct

<i>
</i>RewriteEngine on
RewriteRule ^portal/([^/.]+)/?$ user.php?user=$1


Thanks!!
Copy linkTweet thisAlerts:
@NogDogSep 28.2009 — Looks pretty good to me. But like I said, it's not my area of expertise (if I have one), so I'd have to test it to be sure.
Copy linkTweet thisAlerts:
@jrthor2authorSep 28.2009 — thanks for all the help!!
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...