Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Help

Need to fix a regex line.

         

jkwiz

3:30 am on Jul 12, 2008 (gmt 0)

10+ Year Member



The first is to display a specific page:
/appilcation/{specific_name}/{unique_id}

Both of the variables would always be defined.

The second method is for a category view:
/application/{{category_name}}/{{sorting}}/{{page_number}}

All of the variables would be optional. A user could call the following:

/application

/application/sorting

/application/sorting/23

/application/category_name

/application/category_name/23

/application/category_name/sorting/23

Is it possible to combine both of these somehow?

If not, can at least the URL's listed above work together :)

Heres what I have, but it confuses the category and sorting when one is missing.

RewriteRule ^appc/?([A-Za-z-_]*)/?([A-Za-z]*)/?([0-9]*)$ callback.php?request_type=display&category_name=$1&sort_by=$2&page_number=$3 [QSA,L]

jdMorgan

2:55 pm on Jul 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At minimum, I'd recommend three rules, for the top-level path-part being "sorting," "category_name," and blank.
Put them in order from most-specific pattern to least-specific for best results.

Jim

jkwiz

7:11 pm on Jul 12, 2008 (gmt 0)

10+ Year Member



Ahh, why didn't I think of that. Well is there any way to make these together without getting them confused with each other?

This:
/appilcation/{specific_name}/{unique_id}

With:
/application/{category_name}/{sorting}

jdMorgan

7:54 pm on Jul 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sorry, but I have no idea what values may be present in each field, or which parts are variables and which are literals. Mod_rewrite is based on using patterns to match values, so the simplest (and most inefficient) way to do it would be to make a rule for every possible "specific_name" and "category_name". But of course, that could require hundreds of rules (or more).

However, if the category fields have something in common, and the specific_name fields have something in common, and the category and specific_name fields differ form each other in some identifiable way, then you can use a regex pattern to decide which is which and what is what. You may need to add/use prefixes or suffixes (e.g. "cat"), character ranges (e.g. "[a-z] or [0-9]" or variations) to the URL-path-parts in order to do this.

But since only you know the ranges and values that each of these fields can have, and whether those values "overlap" between fields, you'll have to try to "classify" these fields and their values, with the question in mind, "How do I tell a specific-name/unique-id URL from a category-name/sorting URL by looking only at the URL?"

If the answer is, "I can't," then the problem cannot be solved without introducing some additional 'keys' into the URL, as in the "cat" prefix/suffix mentioned above, or any other method you prefer. Bottom line is that the information to allow determining the "URL-type" must be present (in some form) in the URL itself.

You could of course replace "/application" in the URL with "cat" and "prod" as appropriate, and then rewrite both cat and prod requests to the same callback.php script *after* determining which type of URL you need that script to handle.

When I speak of replacing or adding elements to the URLs, this must be done in the links on your pages themselves, because that is where the URL is defined, and those are the URLs that will be sent to mod_rewrite on your server when the links are clicked.

Jim