-3

This seems to be a Noob question, but still i dont know how to go about with this. Im using node js for my server side development and recently came across SEO friendly URLs. How do i rewrite the URLS which are something like www.abc.com/meet_team.html to www.abc.com/meet-the-team/

One answer would be to use controllers and to route to html pages. This works fine for static web pages.

My problem is with dynamic data. To quote an example, Lets say, yts.ag page has movies stored in the db and it gets retrieved and the url changes dynamically.

For example : www.yts.ag/movies/the-revenant - > This would pick up details about the movie revenant. If the change it to movies/the-dark-knight, it would do so accordingly. Here movies would be the controller, In my Node code, i would handle it something like this.

app.get('/:controller/:movieName', func(req, res){
      // get controller and movie name from req object and query from DB and respond back.
}) 

Now the problem is, i would have stored the name of movie as "The Revenant" in the DB. I would be getting the movie name from the GET request as "the-revenant". How do i query this from the database?

Should i parse the param first? strip the hyphen and then pass it to the DB or any other solution?

Please help me on this. I dont know whether this is the right approach. Thanks in advance.

Pavan
  • 79
  • 11
  • Create a folder `meet-the-team` and put a new `index.html` in it with your desired content. Then you can just open `www.abc.com/meet-the-team` in your browser – Axel Apr 17 '16 at 15:49
  • Clearly need to study more tutorials – charlietfl Apr 17 '16 at 15:53
  • @charlietfl well, instead of telling that, could you mind telling me what i should follow or where im going wrong? Thanks – Pavan Apr 17 '16 at 16:04
  • Your idea is on track. This is not a tutorial service...it's up to you to do basic reading of documentation and framework research. Storing the slug would be a big help but we have no idea what your data model looks like either. Your whole question is far too broad for this site as it currently stands – charlietfl Apr 17 '16 at 16:05
  • Thanks. Will try it out – Pavan Apr 17 '16 at 16:32
  • @charlietfl One last thing. Storing of slug happens while inserting the data to the DB or any procedure later?? If this is cleared, then i guess im good with this. THanks – Pavan Apr 17 '16 at 16:35
  • Yes would be simplest when inserting new item – charlietfl Apr 17 '16 at 16:40

1 Answers1

0

It is as you describe. Now you have to retrieve the movie from the slug reference.

Look for mongo or mysql

martin karl
  • 48
  • 1
  • 7