Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
像wordpress一样重写URL_Wordpress_.htaccess_Url_Rewrite_Permalinks - Fatal编程技术网

像wordpress一样重写URL

像wordpress一样重写URL,wordpress,.htaccess,url,rewrite,permalinks,Wordpress,.htaccess,Url,Rewrite,Permalinks,我已从以下位置重写url: http://www.abc.com/page.php?id=3 致: http://www.abc.com/page/3/ 现在的问题是如何将id值“3”转换为关于tus?(3代表mysql数据库中的“aboutus”)。我们如何检索它并使其成为现实 http://www.abc.com/page/aboutus/ 类似于wordpress的url 请引导我。。非常感谢 您可以将页面URL添加到数据库中 然后在url中传递aboutus: http://www.ab

我已从以下位置重写url:
http://www.abc.com/page.php?id=3

致:
http://www.abc.com/page/3/

现在的问题是如何将id值“3”转换为关于tus?(3代表mysql数据库中的“aboutus”)。我们如何检索它并使其成为现实

http://www.abc.com/page/aboutus/

类似于wordpress的url


请引导我。。非常感谢

您可以将页面URL添加到数据库中

然后在url中传递aboutus:

http://www.abc.com/page/aboutus/
您可以将其设置为:

$sql = 'select * from tbl_pages where id= 3';

...other bits....

$pageUrl = stripslashes( $row['pageUrl'] );

$url = 'http://website.com/page/' . $pageUrl . '/';
在page.php上,您可以查询
id
pageUrl
字段

$id = $_GET['id'];
$sql = 'select * from tbl_pages where pageUrl = "'.$id."';
要将旧url重定向到新url,您可能需要在Htaccess中使用类似的内容:

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^page.php$ page/%1/? [R=301,L]
要将其转换为:
page.php?id=3
page/aboutus/
,您可能需要创建一个使用
id
的登录页,然后从数据库获取url并转发到该登录页

您的Php登录页看起来像:

$sql = 'select * from tbl_pages where id= 3';

...other bits....

$pageUrl = stripslashes( $row['pageUrl'] );

header("HTTP/1.0 301 Moved Permanently");
header("Location: page/" . $pageUrl . "/");
exit;

你能写一点解释的例子吗。。我不太明白你的话。。非常严肃。。谢谢你的耐心,我的朋友。我的朋友在继续上面的示例代码之前遇到了一个问题,我可以知道如何关闭我的旧url吗?人们只能访问新的url,我的意思是。现在两个url都可以输入了,对吗?我希望新的网址只能输入,如果我输入旧的网址,那么我会自动转到新的网址。当我转到旧的网址时,它会将我发送到这个网址。。。