【发布时间】:2013-04-28 12:22:24
【问题描述】:
你好我的mysql表是这样的
[ID] [TITLE] [SEOLINK]
[1] [Test] [test]
[2] [Test 2] [test-2]
我的php url是这样的 example.com/index.php?id=2
如何htaccess重写,所以链接可以 example.com/page/test-2
谢谢。
【问题讨论】:
你好我的mysql表是这样的
[ID] [TITLE] [SEOLINK]
[1] [Test] [test]
[2] [Test 2] [test-2]
我的php url是这样的 example.com/index.php?id=2
如何htaccess重写,所以链接可以 example.com/page/test-2
谢谢。
【问题讨论】:
首先,必须改变mysql的条件。
$query = "select * from TABLE where ID = '".$_GET['id']."'";
mysql_query($query);
to
$query = "select * from TABLE where SEOLINK = '".$_GET['param']."'";
mysql_query($query);
现在,您可以在.htaccess 中使用RedirectRule。喜欢:
RewriteRule ^page/(.*)$ http://example.com/index.php?param=$1 [NC]
【讨论】:
此重写规则将接受格式为 /page/this-is-my-page-title-123 的 URL,其中 123 是页面的 ID。
它也将是 QueryString 感知的(这意味着您可以在末尾添加 ?param=value,这将被处理)
RewriteEngine On
RewriteRule ^page/[\w\-]+(\d)+ /index.php?id=$1 [L,QSA,NC]
【讨论】: