开发者

URL Rewrite like wordpress

I have rewrite a url from:

http://www.abc.com/page.php?id=3

to:

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

开发者_StackOverflow

The question now is how can I turn that id value '3' to be aboutus? (3 is representing 'aboutus' in mysql database)...How can we retrieve it and make it to be

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

Something like wordpress url.

Please guide me.. really appreciate.


You could add a pageUrl into your database

Then to pass aboutus in your url:

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

You would set it like:

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

...other bits....

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

$url = 'http://website.com/page/' . $pageUrl . '/';

On page.php you would query id to the pageUrl field

$id = $_GET['id'];
$sql = 'select * from tbl_pages where pageUrl = "'.$id."';

To redirect your old url to your new url your probably using something like this in your Htaccess:

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^page.php$ page/%1/? [R=301,L]

To turn this: page.php?id=3 into page/aboutus/ though you may have to create a landing page that uses the id, then gets the url from the database and forwards to that.

You Php landing page would look something like:

$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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜