josh.legogeek
04-08-2009, 02:25 PM
Hi,
Is there a .htaccess script that makes no extension like en.wikipedia.org/wiki/Newton?
Thanks,
Josh
If you've got static HTML pages, the easiest way to do it is to enable MultiViews:
Options +MultiViewsThen, 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,
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:
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.