Web Programming Question for Highway Website

Started by cahwyguy, July 03, 2018, 10:27:29 AM

Previous topic - Next topic

cahwyguy

There doesn't seem to be a better place for this.

Currently, over on cahighways.org, I group highways into groups of 8, e.g., 001-008.html . To get to an individual highway, you use 001-008.html#001 or 001-008.html#LR001 (for legislative routes). I'm thinking about moving to a single highway per page to reduce page size, but I don't want to break existing links.

I'd like to get a Javascript that I can put in each nnn-mmm.html file that could (a) take a #mmm if given, rewrite it as mmm.html or mmm.html#LRmmm , and then do an auto reload of that page, and (b) if no reference is given, just go to the first highway's page in the group of eight.

I still need to figure out how I want to rework the indexing, so this isn't immediate, but I'm old-school HTML, not an expert in Javascript (although I have a really thick book on my desk on the subject).

Daniel
Daniel - California Highway Guy ● Highway Site: http://www.cahighways.org/ ●  Blog: http://blog.cahighways.org/ ● Podcast (CA Route by Route): http://caroutebyroute.org/ ● Follow California Highways on Facebook: https://www.facebook.com/cahighways


kurumi

This seems to be what you're looking for: https://stackoverflow.com/a/21198129

The script grabs the hash (the #mmm part) from the original location (request URL) and redirects to the proper page using window.location.replace().

The example uses an explicit old -> new map, but your naming convention looks systematic enough to derive the new URL without having to list the conversions.

(I grouped highways as well in the beginning and in hindsight realized I should have done individual pages from the start.)

My first SF/horror short story collection is available: "Young Man, Open Your Winter Eye"

TheArkansasRoadgeek

I would try one of the Stack Exchange forums I believe it is Stack Overflow.


iPhone
Well, that's just like your opinion man...



Opinions expressed here on belong solely to the poster and do not represent or reflect the opinions or beliefs of AARoads, its creators and/or associates.