Rewrite - Unfriendly URL showing

Discuss practical ways rearrange URLs using mod_rewrite.

Postby RDuno » Mon Dec 15, 2008 10:07 am

The website I have built is very simple.

I don't know much of php, but I managed to setup a simple database containing part-information. This is presented
in an overview list of 200 parts per page and the visitor can click on each part to show the details and to ask for a quotation.

The url shown is the simple php url, i.e. http://www.xyz.com/partdetail.php?id=45

Through .htaccess I can translate http://www.xyz.com/parts-45.html to the above internal url.

The problem I have is that if the visitor follows other links on that page, he will see the internal (unfriendly) url's again. I read
that with help of .htaccess and a php script, it should be possible to change all internal links into friendly url's.

I know it can be done with a php-file which translates url's with help of REQUEST_URI. My problem is that
I lack php-knowlegde to write such a script just like that. I have to do more digging to get make this work.
RDuno
 
Posts: 9
Joined: Thu Dec 11, 2008 6:48 am

Postby richardk » Mon Dec 15, 2008 10:20 am

What you have to do is open the PHP file (in a txt editor, not your browser) with the old link (/partdetail.php?id=45) in it and find where it is echo()ed (outputted). Then you can change it. If you find where the link is outputted and post an example i can show you how to change it.

I read
that with help of .htaccess and a php script, it should be possible to change all internal links into friendly url's.

If you are referring to this FAQ post then that is a different situation. The important variable, 45, is still in the URL. The script is not to change the outputted links.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby RDuno » Tue Dec 16, 2008 2:31 am

That echo link statement is not there. That is my fault, as a php noob I didn't know it should be there. :(

This php-page gets information from a parts-database with help of an unique ID. It is a simple table containing ID, partnr, description and brand fields.

The code of the php-page is shown below. I have editted a bit to make reading a bit easier:
Code: Select all
<html>
<head>
</head>


<body bgcolor="#003465">

<table bgcolor="#1E5C99" align='center' width='781' border="0">
<tr> 

******** editted *********** no php script **********

<?php
//Include our login information
include('../admin/configure.php');

// Connect
$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){
die("Could not connect to the database:
<br />". mysql_error());
}

// Select the database
$db_select = mysql_select_db($db_database); if (!$db_select){
die ("Could not select the database:
<br />". mysql_error());
}

$request = mysql_query("SELECT * FROM ciscoparts WHERE id='$id'");


//Results per page: **EDIT LINK PATH**
echo "<table width='750px' font='Arial' align='center' border='0'>";
while ($row = mysql_fetch_array($request, MYSQL_ASSOC)){
$partnumber = $row["partnumber"];
$description = $row["description"];
$brand = $row["brand"];
$parthdr = $row["partheader"];


**** no important php scripting beyond this point, only page layout ****

</table>
</body>
</html>
RDuno
 
Posts: 9
Joined: Thu Dec 11, 2008 6:48 am

Postby richardk » Tue Dec 16, 2008 6:48 am

That echo link statement is not there.

It won't be exactly how i posted it. It can be any way of echoing a variable in to HTML.

**** no important php scripting beyond this point, only page layout ****

It's likely outputted in there. Post it or look for any "href="s.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby RDuno » Tue Dec 16, 2008 9:54 am

Sorry richardk,

This all the php-coding there is for this page. The html code I skipped doesn't contain anything interesting.

But, looking to the previous page I realize that maybe there the url is determined. This page shows all parts
of a specific brand (200 parts per page). Visitors can click on the partnumber and then the partsdetails page is
showed, i.e. www.xyz.com/ciscopartsdetail.php?id=45.

Looking at this summary page, I can see the following line:
Code: Select all
echo "<td valign='top'>
<font color='black' face=Arial, Helvetica, sans-serif size=2>" . '<a href="' . 'ciscopartsdetail.php?id=' . $row['id'] . '">' . $row['partnummer'] . '</a>' . "</font></td>";


So, I guess here is where the url needs to be specified, right ?
RDuno
 
Posts: 9
Joined: Thu Dec 11, 2008 6:48 am

Postby richardk » Tue Dec 16, 2008 10:01 am

That looks like it (if it's supposed to start with cisco). So try replacing
Code: Select all
'<a href="' . 'ciscopartsdetail.php?id=' . $row['id'] . '">'

with
Code: Select all
'<a href="' . '/ciscopartsdetail/' . $row['id'] . '.html">'
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby RDuno » Wed Dec 17, 2008 4:11 am

That's it richardk, :P

Thank you very very much, you pointed me in the right direction. I am now
able to display html pages instead of php pages using htaccess and a little change in my php-script.

Again thank you for your patience and help. I appreciate it very much. :D

Regards,
RDuno
RDuno
 
Posts: 9
Joined: Thu Dec 11, 2008 6:48 am

Previous

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 1 guest

cron