0

I am using UrlReqritingNet to include url routing in my asp.net 2.0 application.

I want to change

http://mysite.com/book/detail.aspx?id=4

to this:

http://mysite.com/book/a-tale-of-two-cities

The book is stored in a database, 4 being the the unique primary key of the book.

However using this url I am forced to do a database lookup using the book's name rather than the id. I'd much prefer to use the unique id instead.

The obvious solution is:

http://mysite.com/book/4

or

http://mysite.com/book/a-tale-of-two-cities?id=4

Taking SEO in to consideration, are either of those urls ideal?

Thanks

2
  • Do you mind if I ask what CMS you are using? "detail.aspx?id=" looks familiar to me. Commented Sep 13, 2011 at 20:19
  • I'm not using a CMS. The above is a completely hypothetical example. I guess detail.aspx is a popular page name ;) Commented Sep 13, 2011 at 20:23

2 Answers 2

2

Why not do it exactly as StackOverflow does on this very page?

http://mysite.com/book/4/a-tale-of-two-cities?id=4

Put the ID in the URL before the slug. That way if the slug is ever cut off you still have everything you need to retrieve that page.

Sign up to request clarification or add additional context in comments.

2 Comments

I like that idea. I don't even need the query string parameter if I use this technique.
What I like even more is if you change the slug, it redirects to where you should be based on the id number
1

Another consideration of URL rewriting is creating "hackable" URLs so users could possibly navigate your site by guessing the URL.

http://mysite.com/books/detail/a-tale-of-two-cities

You could then query your books data table using the title of the book. If you were to do this however, you would want to ensure that the title is not a SQL injection attempt before running the query (use sql parameters).

From an SEO point of view, this should also be better than having name-value pairs in the URL

3 Comments

I don't think hackable Urls are of much importance for this particular site, as nice as they are. And I'm trying to avoid the need to do a record lookup using a string.
Brian's point is that by using a string lookup you need to be careful about SQL injection, and it's a good one.
Yes it is a good point. I always use either stored procedures or parameterized SQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.