I’m building a site with a hashchange on wordpress, all working good. It just loads a single.php template file into a div.
The problem is that i can still access my single url (http://www.mydomain.com/my-single-post). Since its not having any head and style tags with it, i don’t want people to go over there. Also google has picked up the direct links, because I use the href attribute to load content into the div.
So my question is:
If someone clicks a link lets say in a forum, http://www.mydomain.com/my-single-post , is it possible to redirect him instantly to http://www.mydomain.com/#my-single-post ? I have researched that it has something to do with .htaccess, but I also have Pages, where i don’t want the hash infront of the page-name.
EDIT
I have a small update. If this code removes the hash-tag from the url and redirects to a non-hash url, then how to put this code in reverse?
var current_hash = location.hash;
current_hash = current_hash.replace(/#/,'');
if(current_hash.length>1){
// we have something after the #. redirect as if the # wasn't there.
window.location.href=current_hash;
}
OK, after some trial & error I managed it myself!
This is what I was after:
There’s probably other ways of doing this also, ie. no need for a if / else statement, just to only check if there is a hash.