Jump to content

add or change parametre with seo


UnknownPlayer

Recommended Posts

I have function for add or change parametre in utl(GET), but when i use seo url and mu url goes like this: www.example.com/article/2 and when i click on pagination button where is that function for add or change, i get this url: www.example.com/article.php?id=2&page=2 but i need to url be like this: www.example.com/article/2?page=2

What should i change in this function:

	function add_or_change_parameter($parameter, $value) {
	$params = array();
	$output = "?";
	$firproun = true;
	foreach ($_GET as $key=>$val) {
 		if ($key != $parameter) {
			if (!$firproun) {
	 			$output .= "&";
			} else {
				$firproun = false;
			}
			$output .= $key."=".urlencode($val);
   		}
  	}
	if (!$firproun) {
    	$output .= "&";
	}
    $output .= $parameter."=".urlencode($value);
    return htmlentities($output);
}

 

?

Thanks..

Link to comment
https://forums.phpfreaks.com/topic/249048-add-or-change-parametre-with-seo/
Share on other sites

1. Ditch add_or_change_parameter() in favor of using a built-in function.

2. When you change the page number, first remove the id from the parameters array.

 

So

$url = "/article/" . $_GET["id"];

$get = $_GET; unset($get["id"]); // don't modify $_GET directly
$query = http_build_query($get);
if ($query) $url .= "?" . $query;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.