View Full Version : how to change current url for link

11-18-2007, 10:27 PM
I have pages (created by a php file) in which I want to display the url of other pages, and links to that url.

The url's are very similar. The url of the pages I have is (with varying numbers):

The url I want to display and link to is (with corresponding id number):


In other words, I would like to have a bit of php code that takes the current url and strips out the '2' after "index" and strips '&pop=1&page=0&Itemid=1' out from after "&id=1". Then I can (hopefully) take the resulting url as value from that code to create a link echoing the value as location and as text. To clarify, and this may complicate things, I would like this script to work in all pages and therefore regardless of what the number of the id, pop, page or itemid is in the url.

Unfortunately I have no clue how to do this. Is there anyone who could help me write this bit of php code?

This would realy help me, so many many thanks in advance!

11-19-2007, 12:28 AM
Are you looking for something like this (http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html)?

11-19-2007, 08:49 AM
That's not what I am looking for but I am glad to know about it, and thanks for responding!
Trying to be more specific (at the risk of using terms wrongly because I don't know how to write code and can only understand some of the logic a bit):
I think I need a function that gets the current url, makes a string out of it, changes that string, and turns the resulting string into the value of a variable, and then in the html link I would echo that variable as the href location and as the visible text between the opening and closing a tags.

11-19-2007, 05:21 PM
URL rewriting is your best bet, as what you're asking for is not feasible.

Those parameters will have to be in your URL. Unless you move them to a session variable and never use them in a link.

11-19-2007, 10:17 PM
After hours of researching, learning and trying I managed by writing my first bit of php code ($mosConfig_sitename is Joomla-specific but I think there is some php equivalent to it):

// taking current print version url and creating url of full article
$articleprintversionurl = $_SERVER["REQUEST_URI"]; // getting part of the url to be edited
$urlparttoexplode = substr($articleprintversionurl, 12); // create part of url to be exploded
list($optionpartofurl, $taskpartofurl, $idpartofurl, $poppartofurl, $pagepartofurl, $Itemidpartofurl) = explode("&", $urlparttoexplode); //explode into parts separated by &
$articlefullversionurl = "http://www."; // building up full article url
$articlefullversionurl .= $mosConfig_sitename;
$articlefullversionurl .= "/index.php?";
$articlefullversionurl .= $optionpartofurl;
$articlefullversionurl .= "&";
$articlefullversionurl .= $taskpartofurl;
$articlefullversionurl .= "&";
$articlefullversionurl .= $idpartofurl;

Full page url: <a href="<?php echo $articlefullversionurl ?>"><?php echo $articlefullversionurl ?></a>

It works, so not too bad for a lawyer if I say so myself :D :thumbsup: