A Beginner’s Guide to mod_rewrite.
通常,这将不仅仅是启用mod_rewrite模块(您可能已经为主机启用),然后将.htaccess文件添加到您的Web目录中.一旦你这样做,你只有几条线远离完成.上面链接的教程将会照顾你.
只是为了好玩,这是一个Kohana .htaccess文件重写:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /rootDir/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{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\u0026amp;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)
}
注意第一个正斜杠如何调用一个函数,所有这些都会填充该函数的参数.这真的非常好,使网络开发更加有趣!