2014-03-05 90 views
0

我有這樣一個網址:

http://www.site.com/profile.php?id=$id 

而且我希望它落得像:

http://www.site.com/$id 

我怎麼能在PHP或htaccess的做到這一點?

+0

RewriteEngine在 RewriteRule ^([^ /] *)\。html $ /profile.php?id=$1 [L] – Pratik

+0

使用htacess編寫您的URL方案並將其鏈接到您的php文件中根據URL方案。請參閱http://dzineblog.com/2012/05/build-a-custom-url-structure-with-htaccess-rewrites.html –

+0

謝謝大家。我對技術問題感到困惑。我很感謝你回答我的常見問題。 – Kragalon

回答

1

您將需要創建htaccess的重寫規則如

RewriteRule ([0-9]+) profile.php?id=$1 [L]

這將改寫以0-9字符profile.php任何東西,通過查詢字符串的數量。所以,你可以做

site.com/1

這將是

site.com/profile.php?id=1

1

N多的討論已經在這裏了。無論如何,在這裏。 :)

你htacces重寫規則,

RewriteEngine on 
RewriteBase/
RewriteRule ^([0-9]+)$ profile.php?id=$1 [L] 

方式把PHP文件的鏈接,

<a href="http://www.site.com/$id">Your URL</a> 

確保您的值替換$ ID。

僅供參考,http://www.site.com/profile.php?id=$id也可以工作,避免使用它&使用掩碼URL像我上面引用。 :)