affpro1234 Posted June 17, 2008 Share Posted June 17, 2008 I have converted a database from one script i have to be used for another script. The url stucture of both scripts is different and I need to create a 301 redirect script to run on the new site to send the old linked pages to the new url structured pages. The new converted database holds the new urls in it and I can call them using an article id number which is the same number included at the end of the old url (ie http://www.sitename.com/Articles/title-of-article/1234) I am trying to extract the number from the old url, but am having difficulty...very newbie here. here is the code that I have so far: function getInfo(){ $url = rtrim($_SERVER['REQUEST_URI'], '/'); $urlParts = explode('/', $url); $lastPart = end($urlParts); } $articles = $this->getArticles("article_id = ".intval(getInfo()),'',1); $article = $articles[0]; header("Status: 301 Moved Permanently", false, 301); header("Location: $article->url"); exit; All comments and any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/110507-extracting-a-number-from-an-url/ Share on other sites More sharing options...
btherl Posted June 17, 2008 Share Posted June 17, 2008 You're missing only one thing: function getInfo(){ $url = rtrim($_SERVER['REQUEST_URI'], '/'); $urlParts = explode('/', $url); $lastPart = end($urlParts); return $lastPart; } Link to comment https://forums.phpfreaks.com/topic/110507-extracting-a-number-from-an-url/#findComment-566928 Share on other sites More sharing options...
affpro1234 Posted June 17, 2008 Author Share Posted June 17, 2008 thanks that solved it!! Link to comment https://forums.phpfreaks.com/topic/110507-extracting-a-number-from-an-url/#findComment-567280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.