0

I have a long experience using old techniques in web development, like class ASP, I previously developed a news website long years ago. Now, i want to upgrade it using more advanced techniques (I have strong backgrounds to to re-learn PHP and ASP.Net). My question is: I used to retrieve a page content from database through an ID, like this:

mywebsite.com/NewsID.asp?ID=101

But, I see most websites now use different URL, like BBC today, for example:

http://www.bbc.co.uk/news/world-latin-america-24680283

How to do this?! i.e. not to make my URL like this of BBC not as my classic one

user2888402
  • 77
  • 1
  • 1
  • 9
  • I'm unsure, but if you're using Apache, you may follow [this guide](http://httpd.apache.org/docs/2.0/misc/rewriteguide.html). – Dave Chen Oct 26 '13 at 03:53
  • 1
    You have tagged php and asp.net mvc. Is your question related to how in php or in asp.net mvc? – KrishnaDhungana Oct 26 '13 at 05:42
  • 1
    The answer would be different for each of the 3 technologies you tagged (PHP, ASP.NET, and ASP.NET MVC). You should pick the one most relevant to what you are trying to do. This URL behavior is built-in to ASP.NET MVC, if you check out any basic MVC tutorials. – CodingWithSpike Oct 26 '13 at 14:26

1 Answers1

2

You do so by using routes, that is ways to tell your web server (or other equivalent component) to interpret

http://www.bbc.co.uk/news/world-latin-america-24680283

via a regex or similar tool, to mean

Function name: news
Slug: world-latin-america-
Id: 24680283

And then invoke, for example

news.php?id=24680283

or

public ActionResult News(long id, string slug)
{
   //
}

In a LAMP system, routes can be set by using mod_rewrite as documented in Routing URLs in PHP.

In an ASP.Net MVC context routes are set by calling RegisterRoutes in Application_Start() in your Global.asax.cs.

In the latest version of MVC, you can also use a RouteAttribute that makes everything simpler:

[Route("news/{slug}-{id:int}")]
public ActionResult News(int id) { ... }
Community
  • 1
  • 1
Sklivvz
  • 30,601
  • 24
  • 116
  • 172