嗨,伙计们,我想知道如何使这种请求的服务器,我看了很多网站,他们使用这种技术。例如gametrailers.com => http://www.gametrailers.com/video/level-six-diablo-iii/**721239**
。我知道GET请求是通过使用这样的参数发出的:http://somesite.com/page.php?param=1
。那么如何制作游戏预告片呢?我希望你能理解我的问题,我怀疑"721239"是服务器上的一个文件夹,里面有一个索引页。
您需要在脚本附近的文件夹中创建一个名为.htaccess
的文件在这个文件中,您需要定义重写规则。文件的内容如下:
RewriteEngine on
RewriteRule ^games/(.*)$ games.php?id=$1 [L]
在本例中http://somesite.com/games/213123将转换为http://somesite.com/games.php?id=213123
更方便的方法是重写url。(wiki)
例如,你可以有一个这样的。htaccess,在symfony:
的这个指南中有很好的解释。<IfModule mod_rewrite.c>
RewriteEngine On
# we skip all files with .something
RewriteCond %{REQUEST_URI} '..+$
RewriteCond %{REQUEST_URI} !'.html$
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
您可以在Apache2 (http://httpd.apache.org/docs/2.0/content-negotiation.html)中使用MultiViews来实现这一点。
MultiViews(当启用时)指示Apache在资源不存在时构建参数映射,因此对于www.foo.com/app/game/14,如果www.foo.com/app.php存在而app/game和app/game 14不存在,它可以设置为将其转换为www.foo.com/app.php?type=game&article=14
有些人也使用mod_rewrite,但我不确定这是首选的方法。