/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] using <base> tag breaks anchor links

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:

[code]<base href=”http://mydomain.com/dir1/didr2/dir3/” />[/code]

The problem is that now my anchors are broken. A link like this:

[code]<a href=”#anchor”>link to anchor</a>[/code]

Is now broken. Instead of linking to an anchor within the current file, (let’s call it foo.php) it tries to link to [b][url]http://mydomain.com/dir1/didr2/dir3/#anchor[/url][/b] which would refer to index.html or index.php if any such file existed. If I put in the full path to [url]http://mydomain.com/dir1/didr2/dir3/foo.php[/url] 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?

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@opifexNov 24.2009 — [code=html]
<a href="foo.php#anchor">
[/code]

You MUST href the page when using <base>. The anchor will then apply to that page.
Copy linkTweet thisAlerts:
@sneakyimpauthorNov 24.2009 — Muchas gracias. The mod_rewrite stuff I'm doing makes that a little tricky but I have it working great. Thanks.
×

Success!

Help @sneakyimp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...