Forum Moderators: phranque
I hope that's clear.
Cheers
You can explicitly list the 'pages' you want to rewrite.
Or you can explicitly list the 'pages' you *don't* want to rewrite.
Or you can 'tag' pages to be rewritten/not rewritten with a prefix, most commonly a subdirectory, as in
example.com/rewrite_these/bob or
example.com/do_not_rewrite_these/faq
these subdirectory names are arbitrary, and need not exist as actual subdirectories on the server -- You're just using that part of the URL-path to 'tell' the rewrite rule to take action -- or not.
A good approach would be to use sensible subdirectory names to 'partition' your site into 'real' static pages, and 'virtual' dynamic pages, say by using /pgs/faq and /bob. Then if any request is made to any 'directory' except /pgs, you know it's a dynamic page request. You'll need exceptions for any requests that have a period in them, such as /robots.txt, and for the /w3c directory, where IE will check for your compact privacy policy, and maybe a few others.
Another way to do this, though less (and sometimes much less) efficient, is to test the 'bob' or 'faq' path-part to see if it exists as a directory or a file, and only rewrite those URLs which don't point to a 'real' directory or file. This forces the server to go do a filesystem check to see if the requested resource exists as a file and/or directory, and can be very slow on a busy server. Therefore, I cannot recommend this approach for anything except a 'repair job' on an existing low-traffic site. However, it is accomplished with the -f and -d flags of RewriteCond:
RewriteCond %{REQUEST_FILENAME} -f
Mod_rewrite is not magic; It's based on pattern-recognition using regular expressions. You just have to give the 'pattern recognizer' something to recognize...
Jim
/bob would not be a user user accounts are
used with that tilde ~bob
It would be first considered a file
then a directory (via module mod_speling)
which will add a / to the end of bob
secondly with your rewrites you probably always want
that carat ^ in your pattern match
^ means to start at the beginning
$ end of string
RewriteRule ^/bob$ /user.php?id=bob
If I am on my game tonite....
Regards,
Bugmaster
<Sorry, no personal URLs.
See Terms of Service [webmasterworld.com]>
[edited by: tedster at 3:42 pm (utc) on Jan. 27, 2006]
Welcome to WebmasterWorld!
The use of /~bob would imply that mod_userdir is being used, but that is not necessarily the case. The question is not necessarily related to the operation of mod_userdir and mod_dir. Also, mod_speling and mod_negotiation may or may not be loaded and enabled.
Rather, the question seems to focus on "How do you tell if a URL should or should not be rewritten in mod_rewrite?", and the answer is "By providing an explicit cue that the URL belongs to either the rewrite-desired or no-rewrite class" -- In other words, by providing a character-pattern in the URL that can be recognized (matched) by the regular-expressions pattern-matching in mod_rewrite.
unperturbed,
You may indeed want to look at Apache mod_userdir as a simple way to implement user-based directories.
Jim