Hi,
Is there a .htaccess script that makes no extension like en.wikipedia.org/wiki/Newton?
Thanks,
Josh
Printable View
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:
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.Code:Options +MultiViews
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,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:Code:RewriteEngine on
RewriteRule /wiki/(.*) /wiki.php?index=$1
$_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:
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, setCode:RewriteRule /wiki/(.*) /wiki.php/$1
DirectorySlash offto disable the behaviour.
Thank you SO much!