How come some site urls do not include a file extension?

后端 未结 13 1526
终归单人心
终归单人心 2020-11-28 09:38

I was browsing the internet and noticed, YouTube, for example, contains a URL like this to denote a video page: http://www.youtube.com/watch?v=gwS1tGLB0vc.

相关标签:
13条回答
  • 2020-11-28 10:42

    The normal behavior of a web server is to map the requested URI path onto a file somewhere in the document root directory. So http://example.com/foo/bar is simply mapped onto /path/do/document/root/foo/bar. Additionally, the web server needs to know how to handle a file. This is often done by the file name extension. So files with the file name extension .php are handled by the PHP interpreter.

    Now apart from this normal behavior, most web servers have features that allow to change both the mapping (i.e. URL rewriting) and the way how a file without a file name extension is handled.

    In case of the Apache web server, the former can be done with mod_rewrite:

    RewriteEngine on
    RewriteRule ^/watch$ /watch.php
    

    And the latter can be done with mod_mime:

    <File watch>
        ForceType application/x-httpd-php
    </File>
    

    (Ok, actually this is not mod_mime feature but a core feature.)

    0 讨论(0)
提交回复
热议问题