Forum Moderators: phranque
This is .htaccess file
[b]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^backgroundscategory/(.*)$ backgroundscategory.php?category=$1 [NC,L]
</IfModule>
[/b]
This is the php page with the link change
[b]
<?php
$categoryquery = 'SELECT * FROM backgroundcategory ORDER BY category ASC';
if ($categoryresult = mysql_query ($categoryquery)) {
while ($categoryrow = mysql_fetch_array ($categoryresult)) {
$categorylink = $categoryrow['category'];
echo "<a href=\"backgroundscategory/$categorylink\" class=\"backgroundsfg\">$categorylink</a><br />";
}
}
?>
[/b]
[b]
http://example.com/backgroundscategory/backgroundscategory/backgroundscategory/backgroundscategory/category
[/b]
[edited by: Walley at 2:24 am (utc) on May 1, 2009]
[edited by: jdMorgan at 2:53 am (utc) on May 1, 2009]
[edit reason] example.com [/edit]
Your php is publishing a page-relative link. The browser looking at the page already thinks that it is looking at a page at example.com/backgroundcategory/something (look at the browser address bar to confirm). So, when it sees a relative link of <href="backgroundcategory/somethingelse"> on that page and you click on that link, the browser strips off the "currently-being-viewed-page path" ("something") from the location showing in its address bar, and then adds the contents of the relative link, resulting in a requested URL of /backgroundcategory/backgroundcategory/somethingelse
Each time you click another relative link on a page previously requested by a relative link, you end up going another "/backgroundcategory" level deeper.
The usual solution is to use a server-relative link, instead of a page-relative link:
echo "<a href=\"/backgroundscategory/$categorylink\" class=\"backgroundsfg\">$categorylink</a><br />";
When you do, this, the leading slash tells the browser to discard everything except the protocol and domain in its address bar, and then add the server-relative path to that in order to resolve the canonical URL.
(You could also echo-out a full, canonical URL of "http://example.com/backgroundcategory/$categorylink" if you wanted to. In that case, the browser replaces the entire URL in its address bar.)
See if that helps...
Jim