开发者

Dynamic pages and clean URL conflicts

I did some looking around at how other sites might handle this and didn't really see anything that jumped out at me. I'm working on a project where you can create pages that get linked to from every other page. Here is where the issue is coming up for me.

I'm not sure how I should go about linking to these pages. I've only really thought of two ideas, them being:

  1. website.com/page/My-Page-Name
  2. website.com/My-Page-Name

To note, I'm using mod_rewrite to redirect them to a file that takes the page name as a param开发者_运维百科eter and grabs all the relevant info from the DB and displays it. This is where an issue develops for idea #2.

Idea #1 works and is solid, but I think it's kind of ugly and you don't see a lot of websites that link to other pages of the site with other information padded in the URL.

EDIT for a bit of clarity. The intention of said pages are to be static in the sense they will only ever display what the user sets them to display. They will never except any sort of data in which case pages formatted like in this example would be more appropriate. I'd compare these page more so towards SO's faqs or about page which don't have URLs formatted in this manner.

Idea #2 looks cleaner but runs into some issues when using mod_rewrite and creating said pages.

There are other parts of the site that are linked to that could be mimicked and cause conflicts if you named the page the same. For example, website.com/page1/ points to page1 which already exists, but a conflict would arise if someone wanted to create a page called page1.

So implementing this idea I'd have to filter and limit the user in what page names they could use and at the same time this could make the feature a bit unintuitive and leave them scratching their head. As well as it seems a bit ugly coding it, having an array of unacceptable page names and having to check against it.

The last bit dealing with mod_rewrite to redirect to something like that: RewriteRule ^([A-Za-z0-9-]+)$ getPage.php?p=$1 gets a bit ugly as it gets a bit greedy even while limiting what it'll except.

So does anyone have any insight on any other possible methods to tackle this issue with or how the implementation of one of the two mentioned could be different / better?

Thanks.


I have to agree that Idea #1 (website.com/page/My-Page-Name) is better. It avoids aliasing, and make the rest of the code cleaner (e.g. the rewrite rule simply looks at /page/.*). Among popular sites that use this technique are Wikipedia (http://en.wikipedia.org /wiki/ C), Everything2 (http://everything2.com /title/ Cool+Archive) and Answers.com (http://www.answers.com /topic/ exquisite).

EDIT: Idea #2 could work if you distinguish user pages from built-in pages by case. the path part of a URL is case sensitive, and a rewrite rule can easily check that. Example:

http://example.com/faq <- the website's built-in faq page.

http://example.com/Faq <- a user's page.

http://example.com/Frequently-asked-questions <- another user page.

I'd still go with #1 for simplicity and user-friendliness, but this avoid aliasing at least.


I would go with #1, it's a fairly common convention and avoids potential problems. You said you haven't seen any sites do this, apparently you havent glanced upwards

  (look up)
      ^
      |
http://stackoverflow.com/questions/2121720/dynamic-pages-and-clean-url-conflicts
                         ^^^^^^^^^

other examples:

http://dsc.discovery.com/videos/mythbusters-raw-kari-goes-macgirlver.html
                         ^^^^^^

http://www.hulu.com/watch/115500/the-colbert-report-alicia-keys-and-stephen-perform
                    ^^^^^

Another alternative is to pad the built-in pages and have user generated content be in the url root. And example is the Tcler's wiki:

http://wiki.tcl.tk/_/recent        <-- special page padded with _
http://wiki.tcl.tk/coroutine       <-- user generated content
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜