php中url重写,如何在PHP中重写URL?

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)

}

注意第一个正斜杠如何调用一个函数,所有这些都会填充该函数的参数.这真的非常好,使网络开发更加有趣!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值