I have done much research into the issue, I’m not blindly asking but I can’t grasp this concept. So my website contains a single index.php file that loads data into divs via ajax so the page never refreshes and the url never changes. I now know I need links to certain content using url rewriting. The site contains posts, so for instance all posts are pulled from the db and ‘site.com’ is the url. But I want to be able to do ‘site.com/post-one’ and have that link go to that post. I am thinking first I need to append a variable to the end of the url when the dynamic content for that post is loaded as such: site.com?post=1 so from there I can use url rewrite; the problem I’m having is this. Since the content for post 1 would be loaded into a div, if I went this route, and implemented the url rewrite, would site.com/post-1 now just pull the data dynamically as well or does the page have to be static?
Share
Your problem is that this would necessarily require the use of a hash, rather than a GET variable (because GET requires a page refresh, a hash doesn’t). This is done via the usage of the
window.location.hashvariable in JavaScript, which is updated whenever the URL’s content after a # changes (ex: if I were to changehttp://site.com/#loltohttp://site.com/#lmao,window.location.hashwould change from#lolto#lmao). Hashes are being used commonly in Ajax-based navigation sites, such as Twitter (I think Google’s implementing it as well).If you’re using jQuery, you should try the jQuery BBQ plugin which will allow you to do things such as hash change detection (otherwise, you will have to implement some kind of similar engine yourself, because it will be needed for any kind of hash-based navigation).
You should remember, though, that this doesn’t have anything to do with mod_rewrite, thus you shouldn’t need to add any kind of rewrite rules. All your work (fetching data, etcetera) would be done through Ajax XML HTTP requests, rather than common HTTP requests.
Using this, you could make your url look like
http://site.com/#!/post/1(this could go whichever format you’d like, such ashttp://site.com/#!/p/this-is-the-posts-title) instead ofhttp://site.com/?post=1, although you would be missing onhttp://site.com/post/1.