Forum Moderators: phranque
I'm relatively new to mod_rewrite and am therefore seeking advice on how to create "semi-clean" URLs. By "semi-clean", I mean that would like some of the parameters in my query string to be rewritten within the URL, and some to remain as parameters appended as a query string. Generically, I am looking to rewrite:
[{baseURL}...]
as
[{baseURL}...]
Although I realize that this may sound odd, my reasons for wanting to do this are fairly sound. It is my understanding that one of the main purposes for rewriting URLS is to make them more readable and user-friendly. In my case, I am trying to create a series of web services that perform engineering design calculations. Engineering input parameters are often numeric and thus are LESS readable when the query string is reduced to a URL path. For example, let's say we are designing a bridge beam.
[{baseURL}...] may be considered a "clean" URL, but is ambiguous because one has no idea what 36, 20 and 50 represent. It is arguably more readable, therefore, to write:
[{baseURL}...]
Simultaneously, however, I may not want ALL of the parameters to stay in the query string. Other parameters may describe the beam more semantically, and would therefore be more readable as part of the URL. For example, I would like to rewrite:
[{baseURL}...]
as
[{baseURL}...]
Now, combining the two concepts, I would want to write:
[{baseURL}...]
as
[{baseURL}...]
Can anyone tell me how to do this? Here's what I have so far. I believe I am running into a problem specifically with the first question mark. Apache does not know how to deal with it and, although I have some idea why, I cannot figure out the workaround to achieve what I want.
RewriteRule ^beam/(steel¦concrete)?depth=([0-9]+\.[0-9]+¦[0-9]+¦\.[0-9]+)&width=([0-9]+\.[0-9]+¦[0-9]+¦\.[0-9]+)&length=([0-9]+\.[0-9]+¦[0-9]+¦\.[0-9]+)?$ beam.php?material=$1&depth=$2&width=$3&length=$4
Thanks in advance.
Therefore, you'd need something like:
RewriteCond %{QUERY_STRING} ^depth=([0-9.]+)&width=([0-9.]+)&length=([0-9.]+)$
RewriteRule ^beam/(steel¦concrete)$ /beam.php?material=$1&depth=%1&width=%2&length=%3 [L]
RewriteRule ^beam/(steel¦concrete)$ /beam.php?material=$1 [QSA,L]
Jim