0

I am unsure if it's possible to simply do some replace inside php or if i should look at .htaccess for this? What would be the best solution to clean up this url as desired.

The reason why this is not a duplicate is because i dont have a static url, the id's and text will be changed depending on what post is clicked on the website.

i have tried to do this with .htaccess but it doesn't work for me since i fetch different titles and id's depending on what post users decide to watch. this is how my href looks like

<a href="index.php?page=viewpost&id=<?php echo $row['postID'] ?>&title=<?php echo $row['postTitle'] ?>"><?php echo $row['postTitle'] ?></a>

I would like to know how i would change this url for example

www.website.com/index.php?page=viewpost&id=26&title=title%of%the%post

to

www.website.com/index.php?page=viewpost/26/title_of_the_post

Emoless96
  • 103
  • 10

1 Answers1

-1

you didn't really explain what you are trying to do but here's how to exactly what you ask for.

<?php 
 $url  = "www.website.com/index.php?page=viewpost&id=26&title=title%of%the%post";
 $parts = explode('?',$url);
 $url = $parts[0] . '?page=' $parts[1] ;
 unset($parts[0]);
 unset($parts[1]);
 foreach($parts as $key => $part) {
 $url .= '/'.$part;
 }
 echo $url;
 ?>
azjezz
  • 3,827
  • 1
  • 14
  • 35
  • Im getting call to undefined function expload, and the point is to set the $url in the href, and il remove the www.website.com/ part. – Emoless96 Jan 05 '18 at 13:05