Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite keeps repeating pattern

when clicking links

2:20 am on May 1, 2009 (gmt 0)

New User

5+ Year Member

joined:May 1, 2009
votes: 0

I've been trying to figure this out forever but can't seem to find anything. I'm using XAMPP.

This is .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^backgroundscategory/(.*)$ backgroundscategory.php?category=$1 [NC,L]

This is the php page with the link change

$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 />";

The problem is when the link is click it keeps adding backgroundscategory/ to the url... so if I keep clicking the links from that while loop the url will end up looking something like this:


[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]

2:52 am on May 1, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

It is the client (e.g. browser or search engine robot) that resolves relative links on the pages it displays in order to produce the canonical URLs that it requests when you click on one of those links.

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


4:27 am on May 1, 2009 (gmt 0)

New User

5+ Year Member

joined:May 1, 2009
votes: 0

Thanks for all the information.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members