开发者

Url rewriting and querystring parameters

开发者 https://www.devze.com 2023-04-04 10:40 出处:网络
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

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.

开发者_StackOverflow社区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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号