0

Okay so there are solutions for this as in Modify the URL without reloading the page but I have one question regarding this.

So here is what I plan to do (let's assume my web address is example.com) 1. using pushState I plan to change the browser address to example.com/myprofile/myalbum. So to be clear, this new url may or may not exists but the browser address is changed regardless. In our case this url doesn't actually exist but we are using the address to mark a changed state of the webpage. 2. use ajax to load data regarding "myprofile > myalbum" to the same page.

But now here's the issue I have been thinking about. What if a user loads example.com/myprofile/myalbum directly on a, let's say, new tab. This page clearly throws a not found error because it doesn't exist.

So how do I load ajax corresponding to this fake url? For example http://www.usatoday.com/news/ seems to do this well (unless that's an iframe, which wouldn't be so nice).

Community
  • 1
  • 1
pewpewlasers
  • 3,025
  • 4
  • 31
  • 58

1 Answers1

1

You can add rewrite rules to your webserver, converting either specific URL's or some matching a pattern to something that your scripts can use to show the right page. You can have it rewrite the URL only internally, so the user still see the original URL in the browser. Such as:

RewriteRule /myprofile/(\w*) /index.php?path=/myprofile/$1

Different webservers will probably have different syntax, but they will be similar.

thebreiflabb
  • 1,504
  • 10
  • 19