AbhinavDubey Posted April 7, 2013 Share Posted April 7, 2013 I have a website called gapagap.com developed using php. What is basically want is to change the url pattern from: http://www.gapagap.com/gag/54 To this: gapagap.com/gag/then-why-am-i-not-a-millionaire-yet So what I basically want is to add the post title in the end of the url instead of the post sequence number. Link to comment https://forums.phpfreaks.com/topic/276639-add-post-title-in-the-end-of-url/ Share on other sites More sharing options...
gristoi Posted April 7, 2013 Share Posted April 7, 2013 And I want a big house and fast car, but i want dosent get. You want help then give more information than just i want!! What framework is the site built in? this would be a good start, or at least the section of code that deals with the routing Link to comment https://forums.phpfreaks.com/topic/276639-add-post-title-in-the-end-of-url/#findComment-1423381 Share on other sites More sharing options...
AbhinavDubey Posted April 7, 2013 Author Share Posted April 7, 2013 include("include/config.php"); include("include/functions/import.php"); $thebaseurl = $config['baseurl']; function getPageUrl(){ static $pageURL = ''; if(empty($pageURL)){ $pageURL = 'http'; if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')$pageURL .= 's'; $pageURL .= '://'; if($_SERVER['SERVER_PORT'] != '80')$pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; else $pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; } return $pageURL; } if (is_numeric($_REQUEST['pid'])) { $pid = $_REQUEST['pid']; STemplate::assign('pid',$pid); } else { $error = $lang['138']; } Here it is. There isn't any framework used. The code is developed using a normal text editor. Link to comment https://forums.phpfreaks.com/topic/276639-add-post-title-in-the-end-of-url/#findComment-1423383 Share on other sites More sharing options...
AbhinavDubey Posted April 7, 2013 Author Share Posted April 7, 2013 I developed this code To add the php file function create_slug($string){ $string = preg_replace( '/[«»""!?,.!@£$%^&*{};)]+/', '', $string ); $string = strtolower($string); $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string); return $slug; } $slug = create_slug('This is my page title'); echo $slug; To htaccess file RewriteEngine on RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?slug=$1 [QSA] Will this help. I haven't tested it yet Link to comment https://forums.phpfreaks.com/topic/276639-add-post-title-in-the-end-of-url/#findComment-1423384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.