views:

67

answers:

4

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 the URL in the first example, but enable a page-not-found scenario?

A: 

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

dttungz
A: 

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

peter p
So for short: have each page check their parameters, and if something goes wrong throw a 404... That might even work.
Michael Wagner
Right, it works. Doing it all the time ;-) Displaying the same content for different URLs is not very SEOed anyway :)
peter p
Hmm, one more problem in light of slebetmans answer: what do I do when a valid parameter has the same value as a valid page? I can serve up the page or just throw a 500 error, but that's going to be one hell of a debug nightmare if it ever occurs...
Michael Wagner
The params I am using are modified, so that the application is able to tell them apart. You could e.g. make all params start lowercase where all pages start uppercase. Or make sure pages never have a minus sign in them, and make sure Parameters have... In my case I am appending the product id to the product name
peter p
A: 

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

/Products/Beverages/Minty-chocolate-drink?get=distributors
slebetman
Wouldn't it be simpler then if I just stuck with .aspx and have the URL look like this: "Products.aspx/Beverages/Minty-chocolate-drink/Distributors"
Michael Wagner
A: 

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.

Jesse