是否需要使用mod_rewrite - 马永占 译

本文介绍了一种不依赖mod_rewrite的URL映射方法,通过在.htaccess文件中配置特定指令,使得请求直接由PHP脚本处理,从而实现静态页面效果。

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.youkuaiyun.com/mayongzhan - 马永占,myz,mayongzhan

原文地址:http://www.phpguru.org/#212

最近php-general mailinglist 正在讨论关于mod_rewrite。我的观点很简单,不需要,请看下文:
/rental/property/23425
你可能认为上面的那个地址是rewrite的结果。你错了。是在.htaccess中使用了如下内容:
<Files rental>
ForceType application/x-httpd-php
</Files>
文件被apache当作PHP脚本来执行。意思是你可以使用REQUEST_URI这个服务器变量来得到提交的URL,然后显示内容。




Recent discussion on the php-general mailing list regarding mod_rewrite. My opinion is that if your needs are simple - it's not necessary. Consider:
/rental/property/23425
You may think that mod_rewrite is necessary here. It's not. Simply place this in a .htaccess file:

<Files rental>
ForceType application/x-httpd-php
</Files>
Now the file "rental" will be parsed by Apache as a PHP script. This means you can use the REQUEST_URI server variable to get the requested URI and show the appropriate content.
This is exactly how the "static" directory is done on this site. It's actually not a directory at all, but a PHP file that looks at the URL and determines the correct content to show.


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值