开发者

Extensionless URLs with Parameters, what about 404s?

I'm creating a new url infrastructure for my sites, and came across this problem:

If I have an extensionless URL like this "/Products/Beverages/Minty-chocolate-drink/Distributors", I can't distinguish parameters from pages...

I can find out which page was called by finding the longest match in my pages and treat the rest as parameters, but what about a page-not-found scenario?

An URL like "/Prodcts/Beverages/Minty-chocolate-drink/Distributors" (note wrong spelling in "Prodcts") will not throw a 404, but instead map to the index page, with all the URL as parameters!

Now, I can segment the parameters with f.ex. [page]/p/[parameters], but that's pretty unstylish and not very user friendly.

Do you see another solution that would keep 开发者_JAVA技巧the URL in the first example, but enable a page-not-found scenario?


If the index page cannot handle a parameter, it could throw a 404 as well, after all, there is no unique content to display for this URL (even though it maps to a page, but the browser and the user do not know that Products is a parameter rather than a directory), so 404 is perfect.

EDIT: obviously this would go for every page, not only for the index page: if an unknown parameter is found: 404


Why do you have to map an invalid URL request to the index page instead of redirecting it to a dedicated error page? The rules would be simpler then


Ambiguity is not a good idea. You're probably better off separating runmodes form parameters:

/Products/Beverages/Minty-chocolate-drink?get=distributors


I'm not sure if this will work, let alone for you.

You can use $_SERVER["REQUEST_URI"]; which will return /Products/Beverages/Minty-chocolate-drink/Distributors

Then split it up with explode:

$para = explode("/", $_SERVER["REQUEST_URI"]);

Which will give you:

Array
(
    [0] => 
    [1] => Products
    [2] => Beverages
    [3] => Minty-chocolate-drink
    [4] => Distributors
)

Hopefully from here you can see where I'm going. I was coming here from an answer, too, so this might not be the best way to go about it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜