Pretty urls for Public Profiles
Permalink
Hi guys,
By pretty urls I mean something likehttp://domain.com/username linking to the user profile.
As I'm building a kind of social network that would be an easy way for my users to share/go to their profiles.
So I was thinking of 2 solutions:
- Simple but dirty:
Create a page for each new user with a special pagetype to display his public details at the root. But that means thousand and thousand of pages at the root. what a mess :<
- Smarter but troublesome(?):
Alter c5 to check if the namepage exists:
is it a single page/page ? no => is it a member page? (check under members/namepage) => no => throw 404 not found
I didn't check yet how c5 handle urls. Maybe it's simpler than I think but I'd like to get your opinion on the matter.
Regards
By pretty urls I mean something likehttp://domain.com/username linking to the user profile.
As I'm building a kind of social network that would be an easy way for my users to share/go to their profiles.
So I was thinking of 2 solutions:
- Simple but dirty:
Create a page for each new user with a special pagetype to display his public details at the root. But that means thousand and thousand of pages at the root. what a mess :<
- Smarter but troublesome(?):
Alter c5 to check if the namepage exists:
is it a single page/page ? no => is it a member page? (check under members/namepage) => no => throw 404 not found
I didn't check yet how c5 handle urls. Maybe it's simpler than I think but I'd like to get your opinion on the matter.
Regards
![](/files/avatars/none.gif)
up :<
I'd probably create a custom package to just display the profile page when someone hits the username URL.
In package controller you can use the on_start() method which is run every time a concrete5 request is made.
You'll need the Request and User objects:
In package controller you can use the on_start() method which is run every time a concrete5 request is made.
You'll need the Request and User objects:
// in your package's controller public function on_start() { $req = Request::get(); // current request // TODO: Do your stuff $user = UserInfo::getByUserName('username'); }
Thank you for your answer Mainio
It's easy this way to redirect to any page when we match the url to the username ! Then we just have to rewrite the target url with htaccess.
I didn't know we could hook on c5 with the package controller, nice tip.
I will put the sources here once I've done it
It's easy this way to redirect to any page when we match the url to the username ! Then we just have to rewrite the target url with htaccess.
I didn't know we could hook on c5 with the package controller, nice tip.
I will put the sources here once I've done it
Hi Hudsonn
Did you ever manage to figure this out? I'm trying to do the same thing myself but don't know where to start.
Thanks Rosie
Did you ever manage to figure this out? I'm trying to do the same thing myself but don't know where to start.
Thanks Rosie
Am I right in thinking the solution suggested below would require you to manually change the htaccess file every time there's a new user?
Pretty-urls for user profile pages should be part of the core. profile/ID/ is not good SEO.
Pretty-urls for user profile pages should be part of the core. profile/ID/ is not good SEO.
No, that hasn't been suggested in this thread.