0
我正在嘗試重寫/example-friendly-url
來顯示/posts.php?id=1
的內容。htaccess - 用php和mysql重寫網址
友好的url值和id都存儲在mysql表中。
這是我到目前爲止已經寫,但不對了:
posts.php:
include('/functions.php');
$post = getPost($_GET['id']);
$param = getSlug($_GET['param']);
的functions.php:
function getPost($id) {
$id = (int) $id;
$query = mysql_query("SELECT * FROM list WHERE id = '$id'") or die(mysql_error());
return mysql_fetch_assoc($query);
}
function getSlug($param) {
$query = mysql_query("SELECT id FROM list WHERE slug = '$param'") or die(mysql_error());
return mysql_fetch_assoc($query);
}
的.htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/posts.php
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^/(.*)$ %{DOCUMENT_ROOT}/posts.php?param=$1 [NC,L]
任何幫助將 非常感激。
最新不對?嘗試回顯你從數據庫中讀取的內容。 – mnagel
提供您想要重寫的URL的示例。 '/ example-friendly-url'沒有幫助。 –
所以重寫加載posts.php,但沒有從數據庫和主頁的內容加載被重寫,我不想要。 – aphextwig