Results 1 to 3 of 3

Thread: .htaccess No Extension

  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default .htaccess No Extension

    Hi,
    Is there a .htaccess script that makes no extension like en.wikipedia.org/wiki/Newton?
    Thanks,
    Josh
    Last edited by josh.legogeek; 04-10-2009 at 09:42 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Last edited by Twey; 04-08-2009 at 05:29 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    josh.legogeek (04-10-2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you SO much!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •