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

后端 未结 13 1693
终归单人心
终归单人心 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:17

    below it what I use in my .htaccess to make the url still run correctly without the HTML or PHP extension.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    

    means that if the file with the specified name in the browser doesn't matching with directory (-d) or files(-f) in your webserver, then rewrite rule below

    RewriteRule ^(.*)$ $1.html
    

    i'm not sure how the below work but I think that after it rewrite with html and if it still not matching it then rewrite with php

    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
    

    if it still not matching it will be show 404 page.

    you also can redirect 404 with the code below in .htaccess

    ErrorDocument 404 /404.html
    

    importance is the code is working in for my site.

    http://mintnet.net/services

    http://php.mintnet.net/home

    those doesn't need the file-extension.

提交回复
热议问题