开发者

Designing for "Pretty" URLs

I'm aware of mod_rewrite methods to convert ugly URLs to pretty. My question is preceding this conversion.

I have not yet developed my website. I would like to design all pages such that the pretty URLs are also pretty on the server side.

I would like to come up with a general rule for ALL pages. Normally all pages are slightly different...

/news/12345                        =>    /news.php?id=1234
/members/Mikhail                   =>    /members.php?name=Mikhail
/subsection/page/banned-members    =>    /subsection/page.php?view=banned-members

In the three examples above the GET variable name is different for each case, and the third example could ALSO be developed to be interpreted开发者_如何转开发 as /subsection.php?file=page&view=banned-members

So my question is: What can I do, from the design point, do have an elegant solution on the client AND server side to create pretty URLs?

Thanks!


A general rule of thumb would be to use a portion of the url to identify resources, and GET parameters for optional modifications to how the resource is presented.

For example, for a user profile url:

/user/joe

and

/user/joe?showfull=1

Both the same resource (the user profile), but the latter specifies how to present the information (show full information about the user instead of the default amount).

Applying this convention to your examples above, I would prefer:

/news/12345
/members/Mikhail 
/subsection/page?view=banned-members


In PHP, one possible solution is to have a central PHP file that processes all the URLs of the site. This script processes the whole URL strings and loads the relevant content. It allows all kinds of rewriting or redirecting to be done in PHP.


Using the ASP.NET MVC framework is the poster-child of "pretty URL" designs

EDIT: Sorry, didn't notice your PHP files... there are a number of PHP MVC frameworks too (though I have no experience with how pretty the URLs look)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜