通常,这只不过是启用mod_rewrite模块(您可能已经在主机上启用了该模块),然后将.htaccess文件添加到您的Web目录中。完成此操作后,您仅需几行之遥即可完成。上面链接的教程将为您服务。
只是为了好玩,这里有一个Kohana.htaccess文件可以重写:
# Turn on URL rewritingRewriteEngine On# Installation directoryRewritebase /rootDir/# Protect application and system files from being viewedRewriteRule ^(application|modules|system) - [F,L]# Allow any files or directories that exist to be displayed directlyRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d# Rewrite all other URLs to index.php/RewriteRule .* index.php/$0 [PT,L]这将执行所有请求,并通过index.php文件引导它们。因此,如果您访问了www.examplesite.com/subjects/php,则实际上您可能正在访问www.examplesite.com/index.php?a=subjects&b=php。
如果您发现这些URL具有吸引力,我建议您进一步走一步,并查看MVC框架(模型,视图,控制器)。实际上,它使您可以将网站视为一组功能:
www.mysite.com/jokes
public function jokes ($page = 1) { # Show Joke Page (Defaults to page 1)}或者,www.mysite.com / jokes / 2
public function jokes ($page = 1) { # Show Page 2 of Jokes (Page 2 because of our different URL)}注意第一个正斜杠是如何调用函数的,后面的所有斜杠都填充了该函数的参数。这真的非常好,让网络开发变得更加有趣!



