Forum Moderators: phranque

Message Too Old, No Replies

URL concatenating with each click

htaccess concatenation problem

         

ianao

4:02 pm on Jul 16, 2012 (gmt 0)

10+ Year Member



Hi

Trying to get my head around .htaccess for SEO friendly URLs.

My problem is that with each subsequent click the old URL stays more or less intact, and the new part is added to the end.

My .htaccess file looks like this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^page/([0-9]+)/slug(.*)\.php$ page.php?pageID=$1&slug=$2 [L]


and my PHP extract looks like this:

$navpagelist.="<li><a href=\"page/".$rownavpages["pageID"]."/slug/".$rownavpages["slug"].".php\">".ucfirst($rownavpages["pagename"])."</a></li>";

So click 1 gives me:
page/1/slug/about-us.php

click2 gives me:
page/1/slug/page/1/slug/about-us.php

click3 gives me:
page/1/slug/page/1/slug/page/1/slug/about-us.php

I guess it might be a '.' or '/' too many (or too little), but I can't seem to get around it.

Can anyone help?

Many thanks

g1smd

4:06 pm on Jul 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Start the link with
href="/


You need to use root-relative links, not page relative links, from now on.

Now would also be a good time to "go extensionless". You don't really need that ".php" bit in the URL do you?

ianao

4:40 pm on Jul 16, 2012 (gmt 0)

10+ Year Member



Hi g1smd.

I managed to get it working with your help.

Thanks so much!