我建立一個網絡論壇,其鏈接如下:使用htaccess的良好的SEO鏈接
http://127.0.0.1/website/comments.php?topic_id=2/create+good+seo+links
鏈接生成的鏈接看起來像這樣
<a href="comments.php?topic_id=<?php echo (int)($forum_topic['topic_id']); >/<?php echo urlencode(htmlspecialchars($forum_topic['topic_head'])); > ">
問:我怎樣才能使鏈接看起來像
http://127.0.0.1/website/comments/topic/create-good-seo-links/2
我試着在.htaccess文件中使用這個代碼:
RewiteEngine on
RewriteBase /website
RewriteRule ^comments/([a-zA-Z0-9_-)/([0-9]+)\.php$ comments.php?id=$1
如果我改變ID爲2,它可以適用於所有整數?由於這是一個論壇,所以會創建很多主題。 –
你不會將id更改爲2,而是將id更改爲「$ 2」,它將匹配'([0-9] +)'規則。 – AlienWebguy