Howto: create homepages and 'subdomains' per user

17 years 9 months ago #15382 by trail
Some webmasters requested that i write up a complete tutorial on creating user home pages and virtual subdomains for your members profiles. Here you go:

Requirement: ModRewrite installed on the webserver, ask your host.

First the easy part, creating userhomepages like www.domain.com/username

Edit the .htaccess file in the root of your webserver

Step 1) turn the rewrite engine on:
[code:1]RewriteEngine On[/code:1]

Step 2) establish the rewriting base and default directory index

[code:1]DirectoryIndex index.php
RewriteBase /[/code:1]

if you have your website in a subdir on your webserver you need to reflect that like so:

[code:1]DirectoryIndex index.php
RewriteBase /subdir/[/code:1]

Step 3) Create the conditions for when to rewrite userhomepages:
The following lines say 'if the request is not a directory nor a real file, continue to rewrite it'

[code:1]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d[/code:1]

Step 4) Actually rewrite the request.
[code:1]RewriteRule ^([^/]+)/?$ index.php?option=com_comprofiler&task=userProfile&user='$1' [L][/code:1]

You are now done creating userhomepages. Lets continue creating virtual subdomains for your users.

Requirement: DNS settings.

You first have to prepare your DNS server to allow all requests for any subdomain to go to your original website. So that means you need to see your website if you type in a rubbish subdomain like asdfasdf.domain.com
Not everyone is knowledgable in DNS but this is where your hosting provider comes in. Ask them to do this for you.

Step 5) Translate username.domain.com to www.domain.com/username

Below Rewritebase and above the rewritecondition add:

[code:1]RewriteCond %{HTTP_HOST} ([^/]+)\.domain\.com [NC]
RewriteCond %1 !www$ [NC]
RewriteRule ^(.*)$ www.domain.com/%1 [L][/code:1]

This translates username.domain.com to www.domain.com/username and does not show username.domain.com in the adress bar, as much as we would like that, it is currently not possible because joomla also uses the subdomain part to generate the login cookie. Entering the site with a different subdomain (not www but username) invalidates the cookie and thus the login.

Now when a request comes in for username.domain.com the rewrite engine first translates it to www.domain.com/username and then rewrites that to www.domain.com/index.php?option=com_comprofiler&task=userProfile&user='username'

Here you can see it in action: tester.djtrail.nl

Happy rewriting!
~Trail.

This post in a file:

Attachment howto.txt not found



Post edited by: trail, at: 2007/03/13 04:32

DJ Trail.
CB Co-Founder & Test-Lead.
Plugins: My Age , Starsign Matchmaking Horoscope , My Visitor , My Highscores , My ProfileID ,
My Components: Import & Invite Karma Casino (Use Test / Test)
My Modules: Many :)
Attachments:

Please Log in to join the conversation.

17 years 9 months ago #15474 by Jelte
Unfortunately this ain't working anymore if your using a SEF component (like OpenSEF).

Please Log in to join the conversation.

17 years 9 months ago #15489 by trail
yes im fighting on ever joomla update to keep this working..

current 109 sef breaks it a bit too.. most works except the redirect after writing a guestbook message.. just replace old 108 sef..

but its worth to fight for it i think..

Post edited by: trail, at: 2006/06/17 19:45

DJ Trail.
CB Co-Founder & Test-Lead.
Plugins: My Age , Starsign Matchmaking Horoscope , My Visitor , My Highscores , My ProfileID ,
My Components: Import & Invite Karma Casino (Use Test / Test)
My Modules: Many :)

Please Log in to join the conversation.

17 years 9 months ago #15505 by ericfoster3
Replied by ericfoster3 on topic Re:Howto: create homepages and 'subdomains' per us
What a neat trick! Thanks for the tip.

CB 3rd Party Developer: DatsoTab | KarmaTab
Joomla! 1.0.10
Community Builder 1.0
joomlaboard 1.1.2

Please Log in to join the conversation.

17 years 9 months ago #15548 by micoots
Hi Trail (and anyone else that knows the answer to this),

trail wrote:

Attachment howto.txt not found



Good luck:)

Post edited by: trail, at: 2006/06/15 20:31


This is a nice piece of work, thank you.

I noticed one thing though, registered users (people logged in) can see and type in the url's no problem, but anonymous web users get the "you need to login" message.

How can I make the profile publicly viewable?

Thanks.

Michael.

Please Log in to join the conversation.

17 years 9 months ago #15549 by micoots
micoots wrote:

I noticed one thing though, registered users (people logged in) can see and type in the url's no problem, but anonymous web users get the "you need to login" message.

How can I make the profile publicly viewable?

Thanks.

Michael.


I spoke too soon. I found the view option in the CB User Profile section, all done and working now :)

Michael.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.195 seconds

Facebook Twitter LinkedIn