Jump to content

Recommended Posts

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. 

Edited by AbhinavDubey
Link to comment
https://forums.phpfreaks.com/topic/276639-add-post-title-in-the-end-of-url/
Share on other sites

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

Edited by gristoi
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.

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.