Python Community Server (development progress)
Running commentary on the progress of the development of the Py-C-S; this blog gets updated when coding goes on. Here is some answers to questions that have come in.
        

Manila-style URLs in PyCS

If you've been to a site like EditThisPage and BlogSpot, you'll notice that every sub-site has its own domain - http://dave.editthispage.com/, for example.  Wouldn't it be cool if you could do that with PyCS?

Well, it seems that you can!  It's a bit of work to get going, but it's not impossible.

Step 1: Set up the DNS record

The first step is to register a domain and to set up DNS hosting.  Set up a wildcard A record (PyCS actually uses a CNAME, but that's a whole 'nother story) to point all subdomains to the same machine:

*.yourdomain.com    A    10.0.0.1

Step 2: Tell Apache where things are

Now go into your Apache config and fire up mod_rewrite.  What you're going to do here is cunningly avoid the necessity for loads and loads of <VirtualHost> blocks by rewriting foo.yourdomain.com and turning the foo bit into a path, e.g. yourdomain.com/foo.

Make a <VirtualHost> block for yourdomain.com:

<VirtualHost>
DocumentRoot /var/www/wherever
ServerAdmin youraddress@yourdomain.com
ServerAlias yourdomain.com *.yourdomain.com
ServerName yourdomain.com
</VirtualHost>

Now the rewriting: add the following after ServerName:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(.+) http://127.0.0.1:5445$1 [P]

This proxies http://yourdomain.com/* through to http://127.0.0.1:5445/* (this connects to the local PyCS that's running on port 5445).  Now the user sites:

RewriteCond %{HTTP_HOST} ^[^.]+.yourdomain.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+).yourdomain.com(.*) http://127.0.0.1:5445/$1$2 [P]

Now cross your fingers and restart Apache:

apachectl restart

Now go to system.yourdomain.com/updates.py and see if you get the updates page.  If you do, it worked!  Now make some symlinks to get some aliases going.

ln -s users/0000001 foo

Now go to foo.yourdomain.com and see if you get what used to be www.yourdomain.com/users/0000001.  If you do, good!

Step 3: Tell PyCS where things should go

Radio and xmlStorageSystem (and thus PyCS) work together to figure out URLs for files.  When Radio sends a file to a community server, the community server sends back the absolute URL for the file.  This lets Radio make links to that file from anywhere, safe in the knowledge that they actually will work.

However, at this point, PyCS is still telling your users' Radios that their blogs are at http://www.yourdomain.com/users/*.  You don't want this!  You want them to go to the proper URLs!  PyCS can do this - just add some aliases into pycs.conf:

[aliases]

0000001 = http://foo.yourdomain.com

Note: you might need to update your PyCS before this will work.  Update from CVS on SourceForge or download the latest distro archive and unpack it over the top of your current PyCS files.

Now restart PyCS and tell your users to do a Radio -> Publish -> Entire Website.  They might need to do it twice, but it sometimes seems to work here on the first go.  Now all the auto-generated links will work.

Step 4: Put in some redirection

Whenever you change links, you should put in redirects to point people (and search engines) in the right direction.  Apache does this with the 'Redirect' command.  Put the following in the <VirtualHost> block for your old domain:

Redirect permanent /users/0000001 http://foo.yourdomain.com

This will point everyone in the right direction.

Problems

It's not perfect - I still haven't got it redirecting properly within sites.  If you go to http://notes.pycs.net/stories, for example, it won't work because PyCS tries to redirect you to http://notes.pycs.net/notes/stories/ instead of http://notes.pycs.net/stories/.  <sigh>

More later, when I've fixed that.



© Copyright 2002 Phil at Myelin. Click here to send an email to the editor of this weblog.
Last update: 2002-04-30; 11:56:46 p.m..