开发者

How does youtube have URL's like these?

YouTube has URL's like these:

http://www.youtube.com/watch?v=zKqeCtjFGFc

When 开发者_StackOverflow社区I create a PHP page mine would be like these:

watch.php?v=zKqeCtjFGFc

How does YT hide the PHP extension, and I know YT is probably written in Python or something other than PHP but I have seen this done in WordPress and other PHP written apps.

Can this be done without using htacess rewrites?


The easiest is to have a directory named watch, and have an index.php file inside that directory. Then /watch would serve the index.php file and by extension your index.php script would get the query parameter v.

A more robust yet complicated way to do it is to use mod_rewrite to rewrite /watch.php to /watch

I haven't tested but a rule like this might do the trick, you'd put this code in your .htaccess file

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/watch$
RewriteRule ^/watch$ watch.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜