0

I am working on a blog. I have an issue where if i go to single post page then i get a URL something like: http://localhost/category/old-Richard-McClintock/4 where 4 is my post id and "old-Richard-McClintock" is my post name.

Now how would i know that a user changed the url from http://localhost/category/old-Richard-McClintock/4 to http://localhost/category/old-McClintock/4 ? I want to load the original url as i am getting data from post id so in both cases, it will grab the data.

StackOverflow is also reloading the page with original URL if we change the content part(question title) without changing question id from URL.

i am using Express with ejs.

Any help will be highly appreciated.

Thanks.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Harpreet Singh
  • 999
  • 9
  • 19
  • Keep an identifier such as a title or url string in the database, then when you fetch the post from the database by using post id compare the url with the identifier, if they don't match redirect the user to the well-formed url page – riyaz-ali Jun 17 '17 at 06:43
  • This has nothing to do with EJS or anything really mentioned in your question. Consider the URL to your own question here `https://stackoverflow.com/questions/44601115/how-to-reload-with-original-url-if-changed-by-user-in-address-bar-in-express-ejs` Which I am going to change the "title slug" in yet you will still see the same question if you called that URL. Because the only thing the site looks up is the `questions/44601115` part, which does not change. That's how we do it. – Neil Lunn Jun 17 '17 at 09:11

0 Answers0