I want to use a # (hash) in my node links, so that users can jump to specific nodes in a list.
How can I prevent # being converted to %23?

Comments

greggles’s picture

Status: Active » Fixed

I believe this is a weakness (and benefit) in the core path module. It will urldecode urls as they come out of the url_alias table which turns the # to the %2523 (or whatever it is...).

1) Visit admin/build/path
2) Add to the path "node/1" the alias "something#stuff"
3) Look in your url_alias table and notice how the # is stored as a # sign
3) Visit node/1 and click on the "View" tab - you will be directed to something%2523stuff

So...it's beyond Pathauto.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

hermes_costell’s picture

Leveraging custom_url_rewrite_outbound:

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
	$replacement_string = "YOUR-STRING-HERE";

	$strip_start = strpos($path, $replacement_string);
	if($strip_start){
		$replacement_string_length = strlen($replacement_string);
		$start = $strip_start + $replacement_string_length;
		$length = strlen($path) - $start;
		$after_replacement = substr($path, $start, $length);
		$path = substr($path, 0, $strip_start);
		$options['fragment'] = "#".$after_replacement;
	}
}
  • Place the above code into your settings.php file
  • Then go into admin/build/path/pathauto
  • For the node type(s) you want to have the hashmark place your replacement_string above into them in the Node Paths section in the spot where you want the hash mark to occur.
  • Use your preferred method to update the urls.

Note: this isn't just a 5.x issue - it's at least a 6.x issue as well - but there appears to be no way to accommodate that via the architecture.