Obviously, YOU have to create the links to those pages without the .php extension.
Dan,
NICELY DONE!
RewriteEngine On
# turn on the mod_rewrite engine
RewriteCond %{REQUEST_FILENAME}.php -f
# IF the request filename with .php extension is a file which exists
RewriteCond %{REQUEST_URI} !/$
# AND the request is not for a directory
RewriteRule (.*) $1\\.php [L]
# redirect to the php script with the requested filename
If you want something for a generic URI like that (lowercase characters only), try:
RewriteEngine on
RewriteRule ^user/([a-z]+/([a-z]+)$ user.php?$1=$2 [L]
It’s all very simple when you can specify exactly what you want and understand enough regex to translate it to code. If you can’t, try the Article in my signature.
I do not want to hard-code the user.php file in the .htaccess since the page name can be anything, so is it possible to to have /var/value type parameters without hard-coding the file name?
What about when you want more than one /var/value on the end of the URL? At some point your rules are going to be too complex to want to manage them as rewrite rules, and you should just edit your .php files to look at the URL and parse them there.
Most sites with completely arbitrary URLs that can map to many different actions just rewrite all requests to a single file, and that file’s job is to parse the URL and invoke the correct code.
Too true! However, that’s a “cheat” which involves much more sophistication by the member who was only asking a simple mod_rewrite question. If he still wanted to use other scripts, “user” above could have been made a variable, too, in the regex and redirection (and remained a very simple question).