如何在php中创建友好的URL?通常,显示某些配置文件页的做法或非常老的方法如下:www.domain.com/profile.php?u=12345哪里u=12345是用户ID。最近几年,我发现了一些网址很好的网站,比如:www.domain.com/profile/12345如何在PHP中做到这一点?就像一个疯狂的猜测,这是否与.htaccess档案?您能给我更多的提示或一些关于如何编写.htaccess档案?
2 回答
![?](http://img1.sycdn.imooc.com/5458477300014deb02200220-100-100.jpg)
临摹微笑
TA贡献1982条经验 获得超2个赞
.htaccess
RewriteEngine onRewriteRule ^/news/([0-9]+)\.html /news.php?news_id=$1
/news.php?news_id=63
/news/63.html
forcetype
.htaccess
<Files news> ForceType application/x-httpd-php</Files>
$_SERVER['PATH_INFO']
<?php echo $_SERVER['PATH_INFO']; // outputs '/63.html'?>
![?](http://img1.sycdn.imooc.com/545845d30001ee8a02200220-100-100.jpg)
青春有我
TA贡献1784条经验 获得超8个赞
<IfModule mod_rewrite.c># enable rewrite engine RewriteEngine On # if requested url does not exist pass it as path info to index.php RewriteRule ^$ index.php?/ [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php?/$1 [QSA,L]</IfModule>
foreach (explode ("/", $_SERVER['REQUEST_URI']) as $part){ // Figure out what you want to do with the URL parts.}
- 2 回答
- 0 关注
- 719 浏览
添加回答
举报
0/150
提交
取消