Hash character in URLs (accessing and redirecting in Apache) Hash character in URLs (accessing and redirecting in Apache) apache apache

Hash character in URLs (accessing and redirecting in Apache)


A hash character in the URL specifies the anchor, and it's not even sent to your webserver. A redirect is impossible on the server side, and the old developer probably did it using JavaScript. Implement fallback URLs without the hash instead, and have a global JavaScript script detect these URLs and redirect automatically.


Hash tags cannot be read by the server. They are regarded as locations within the document and are therefore not exposed to the server. The client is the only one whom see's these. The best you could do is use a "meta refresh" tag, or alternatively, you could use javascript to detect the url, and if its one which requires 301 redirection, use "window.location" to move the user to a full url where mod_rewrite or a php page can issue a 301 header.

However neither are SEO friendly and only really solve the issue for users that click onto an old link via an external site

<!-- Put in head tag so the page does not wait to load the content--><script type="text/javascript">if(window.location.hash != "") { var h = window.location.hash.match(/#\/?(.*)/i)[1];switch(h) {    case "something_old":        window.location = "/something_new.html";    break;    case "something_also_old":        window.location = "/something_also_new.html";           break;  }}</script>