Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Rewrite on user folders

7:15 pm on Oct 20, 2006 (gmt 0)

10+ Year Member

I'm having a really hard time trying to do a mod_rewrite on user directories. The webroot is /www/html/ and the user directory is /www/user/. So if you go to the URL http://www.example.com/~jimbob/ it goes to the user directory /www/user/jimbob/public_html/.

I've tried putting an htaccess file in /www/html, /www/user, and /www with no success. I've also tried putting it in the httpd.conf file. I'm just trying to redirect some old usernames to new ones.

Please help me. :)

2:59 am on Oct 21, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

If you've put code in httpd.conf, and it doesn't work, then the problem is with the code itself, or with other server configuration settings that are preventing that code from running. Or perhaps you don't have the modules loaded that are needed to prcoess your directives.

From your example URLs, it looks like you're using mod_userdir, so you might want to review the Apache documentation on that module for a start.

Based on what you've written, that's all I can come up with.


1:35 pm on Oct 24, 2006 (gmt 0)

10+ Year Member

Thanks jd. Here's a code snipit I've tried.

RewriteEngine On
RewriteRule ^([^\.]+[^/])$ /$1/ [R]
RewriteRule ^~jbob/$ /~jimbob/ [R]

Note I also had a wildcard in the 3rd line to catch all files and folers within jbob, but I've taken it out for simplicity and http://www.example.com/~jbob/ should redirect, and it doesn't.

I've also tried it without the ~. The 2nd line makes sure that folders end with a / so that the 3rd line works. I believe the problem is that the server just interprets the ~ and it doesn't need to match on it. Or the problem may be about where I need to put the .htaccess file. But then again, I've tried it without the ~ and in different folders.

I hate the apache documentation too. Any more ideas?

2:05 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

You can hate the documentation all you like, but it is what it is. You'll find you like it a lot better once you're more accustomed to Apache, which takes study, experimentation, and time... At that point, the fact that it is short and sparse becomes an asset rather than a liability, because it's easier to find specific info in a short document. I've read *all* of it many times, and have come to appreciate its compactness.

The root problem you're having is likely this:

You are using mod_userdir, as evidenced by the fact that you state that "~" URLs are mapped to subdirectories. This only happens "automatically" if you're using mod_userdir, and is not the default configuration on Apache.

So the problem is that mod_userdir kicks in and maps these "~" URLs to the subdirectories before mod_rewrite ever gets a chance to run, therefore rendering it ineffective.

There are several options, some of which may be available to you on this host, depending on what they allow you to do. In no particular order:

  • Disable mod_userdir, and replace its functionality with a simple mod_rewrite rule when needed.
  • Change the LoadModule order so that mod_userdir loads before mod_rewrite, and therefore will run after mod_rewrite. (This applies on Apache 1.x only, not on Apache 2.x).
  • Dump the "~" approach entirely, and replace it with "account name" URL prefixes that are tagged with "user" or "member" or something other than "~", thus bypassing mod_userdir. Again, you'll need to replace the name-to-subdirectory mapping function with a simple mod_rewrite rule, e.g. rewrite the URL example.com/user-bob/path to the filepath /users/bob/path and then place all user files into name-based subdirectories in the /users subdirectory. The "user" URLs you use can be tagged any way you like, as long as the tagged URL can be uniquely-identified by a mod_rewrite pattern as needing to be rewritten to a subdirectory of the /users subdirectory. The above "user-bob" URL is just one example.



    Featured Threads

    My Threads

    Hot Threads This Week

    Hot Threads This Month