[_] Any Apache PHP Wizards?
Vincent Bray
noodlet at gmail.com
Thu Jan 3 19:02:38 GMT 2008
On 03/01/2008, Sam Machin <sam at bs8.org.uk> wrote: > Hi _ > > I'm trying to build a site/service and I want to be able to have > usernames ulrs, e.g. http://foo.com/sam > > I've worked out how to pass parameters as slashes in the URL eg > foo.com/user/sam where user is a php script but I'd like to do it on > the top level. > > Currently I've defined a custom 404 page in .htaccess and I'm using > the $_SERVER['REDIRECT_URL'] variable to get the username. Presumably you used ErrorDocument to specify the custom 404 handler. That won't work with POST requests (or any requests with an entity). > However I'm rather aware that hacking the 404 isn't really an ideal > solution, anybody know how to do it properly? It's possible to have /user.php called for /user/bob automatically by setting Options MultiViews, but you want to drop the /user/ part as well. > FYI I'm running apache1.3 on a MacOSX box and I've got root access. I'd highly recommend building 2.2 instead, but that shouldn't be an issue for this task. So, with mod_rewrite: RewriteEngine On RewriteCond %{REQUEST_URI} !whatever.php RewriteRule ([^/]+) /whatever.php That'll stop requests like /images/foo.png from being rewritten, but of course any requests like /foo will be. That's not ideal, but that's what you asked for :-) I'm always on #apache on the freenode irc network, just ping noodl. -- noodl