Click to See Complete Forum and Search --> : [RESOLVED] using <base> tag breaks anchor links


sneakyimp
11-23-2009, 11:55 PM
I have been working on some mod_rewrite stuff which rewrites my ugly urls into nice SEO-friendly ones. Because the directory structure of the rewritten urls is different than the dir structure on my server, my images (and CSS and Javascript) were broken.

I fixed the image/css/javascript breaking problem by using a <base> tag:
<base href="http://mydomain.com/dir1/didr2/dir3/" />

The problem is that now my anchors are broken. A link like this:
<a href="#anchor">link to anchor</a>

Is now broken. Instead of linking to an anchor within the current file, (let's call it foo.php) it tries to link to http://mydomain.com/dir1/didr2/dir3/#anchor which would refer to index.html or index.php if any such file existed. If I put in the full path to http://mydomain.com/dir1/didr2/dir3/foo.php then clicking one of these links re-loads the current page rather than just jumping to the anchor.

Is there any way to fix this problem?

opifex
11-24-2009, 01:32 AM
<a href="foo.php#anchor">

You MUST href the page when using <base>. The anchor will then apply to that page.

sneakyimp
11-24-2009, 01:38 AM
Muchas gracias. The mod_rewrite stuff I'm doing makes that a little tricky but I have it working great. Thanks.