如何在php中創建友好的URL?通常,顯示某些配置文件頁的做法或非常老的方法如下:www.domain.com/profile.php?u=12345哪里u=12345是用戶ID。最近幾年,我發現了一些網址很好的網站,比如:www.domain.com/profile/12345如何在PHP中做到這一點?就像一個瘋狂的猜測,這是否與.htaccess檔案?您能給我更多的提示或一些關于如何編寫.htaccess檔案?
2 回答
臨摹微笑
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'?>
青春有我
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 關注
- 741 瀏覽
添加回答
舉報
0/150
提交
取消
