Why do links to anchor tags in my pages turn the # into %35, and thus break?
March 18, 2005 5:23 AM   RSS feed for this thread Subscribe

Why do links in my anchor tags turn the # into %35 and thus break? Any idea why - and (most importantly) how to fix it. (yeah, I know I should scrap this cumbersome system and move to WordPress - it's my plan, but I don't have time at the moment).

I use a crude system for permalinks: each post on a page has a different anchor. I set up permalinks www.myblog.com/thispost. When I publish, I use control panel 2 to make a permanent redirect, so www.myblog.com/thispost redirects to www.myblog.com/thepage.htm#thispost. This adds a line in my .httaccess file.

New ones, however, turn up in the browser address bar as %35 instead of the # symbol, and therefore break and 404. (same in IE and Firefox)

Old ones still work fine. I've tried using notepad to copy an old redirect line from httaccess, and just amend it to a new one, but they break too.
posted by Pericles to computers & internet (12 comments total)
Can you post an actual redirect line from your file?
posted by cillit bang at 6:43 AM on March 18, 2005


Sorry if I'm missing something obvious, but why not just delete the redirects and use the URLs with the fragment identifier in them as your permalinks? It may not look as pretty, but the current system sounds like a name collision waiting to happen even when it works.
posted by boaz at 11:53 AM on March 18, 2005


Are you editing the HTML yourself, in Notepad or some other text editor, or are you using an HTML editor of some kind? If the latter, it seems like it's doing a URL encoding on it. If not, and the anchor tag in the page is being saved with the # in it, I can't imagine why (or where, for that matter) it would be getting encoded.
posted by cerebus19 at 12:44 PM on March 18, 2005


Here's a "permalink" that works (not linked, so as not to self-link) http://brucelawson.co.uk/xmas satisfactorily resolves to http://brucelawson.co.uk/index.htm#xmas.
The redirect is

Redirect permanent /xmas http://brucelawson.co.uk/index.htm#xmas

This redirect http://brucelawson.co.uk/hahk fails, because the browser tries to go to http://brucelawson.co.uk/index.htm%23hahk - which doesn'[t exist. The redirect in .htacces

Redirect permanent /hahk http://brucelawson.co.uk/index.htm#hahk

.. so I can't see why it fails.

(The reason I don't use the real url is so that I can move old links from index.htm to archive.htm and change the redirects so that the permalinks don't die.)
posted by Pericles at 12:58 PM on March 18, 2005


I'm using Dreamweaver MX2004 or Notepad to write the html.

I'm editing Control Panel X to get at my htaccess file.
posted by Pericles at 1:04 PM on March 18, 2005


Both the redirected URLs you posted work fine for me. (Firefox & Safari on OS X.)
posted by boaz at 3:21 PM on March 18, 2005


I still say you should, at the very least, move your permalinks out of the top level of your namespace. Then you can just use a single RedirectMatch to do your redirection. For example, if you changed your permalinks to the form http://brucelawson.co.uk/p/thispost, then you could replace all your redirect lines with the single line RedirectMatch /p/(.*)$ http://brucelawson.co.uk/index.htm#$1
posted by boaz at 3:27 PM on March 18, 2005


Whoops, I just tried that RedirectMatch, and that did have the problem you mentioned. [this is odd]
posted by boaz at 3:40 PM on March 18, 2005


The "#" is not processed by the server. It is an illegal character as far as the web server is concerned. The "#" anchor is only processed on the client side (the browser finds the anchor after the page loads).

So, basically, I don't think you can do what you are trying to do (pass an URL with the # to the server through the .htaccess redirect. The server will ignore everything after (and including the pound sign).

Put another way: When you click a link that says "http://whatever.com/whatever.html#anchor" the web server looks for the page whatever.html (not a page named "whatever.html#anchor" (cause that page doesn't exist). So it is probably trying to URL encode the # character based on your character set or something.

I'm guessing here, but I can't find any .htaccess redirect tutorials that tell me how to do what you are trying to do here.
posted by spock at 8:18 PM on March 18, 2005


OR guess what:
Comments in .htaccess files begin with the pound sign '#'.

When the .htaccess file encounters a # sign it interprets it as the beginning of a comment. Everything from that point on in the line will be ignored.
posted by spock at 8:31 PM on March 18, 2005


Which (I think) explains why my previous comment is basically correct.
posted by spock at 8:52 PM on March 18, 2005


Thanks all. But nothing explains why some of the "permalinks" work. Time to bring forward that move to WordPress, methinks!
posted by Pericles at 2:33 AM on March 19, 2005


« Older Every so often a finger on my ...   |   What are some good companies t... Newer »
This thread is closed to new comments.