If you've got static HTML pages, the easiest way to do it is to enable MultiViews:
Code:
Options +MultiViews
Then, for an URL /dir/foo, Apache will try to load /dir/foo.html. You can also use this to provide alternative versions of the same document to browsers whose settings indicate that they prefer it, such as /dir/foo.html.fr or /dir/foo.pdf. This does mean that multiple files with the same filename before extension get treated a bit specially, though.
If you have dynamic pages to which you want to feed the path as a variable, however, mod_rewrite will serve you better; for example,
Code:
RewriteEngine on
RewriteRule /wiki/(.*) /wiki.php?index=$1
You can also pretend your script is a directory, and let it decide what to output based on the path, passed in the environment variable PATH_INFO for CGI scripts (PHP: $_SERVER['PATH_INFO']
; other methods, like FastCGI or mod_wsgi, may differ): going to /wiki.php/Newton will, if wiki.php exists, run /wiki.php with $_SERVER['PATH_INFO']
equal to 'Newton'
; this can be rewritten too to remove the .php from the path:
Code:
RewriteRule /wiki/(.*) /wiki.php/$1
Beware, though, that when using dynamic pages with no extension, Apache will by default redirect /foo/bar to /foo/bar/ on the client-side, and in doing so lose any form data that was meant to be posted to the page. If you're having this problem, set DirectorySlash off
to disable the behaviour.
Bookmarks