Rewrite Unlimited Query

Is there a way to have a mod rewrite to make friendly query strings


something/brooklyn/ny/11214/hi/another full example
something/brooklyn/ny/11214/hi/ just 1 keyword
something/brooklyn/ny/ just city and state

with my limited knowledge i would have to do something like
RewriteRule ^something-([^-][a-zA-z0-9_])$ /search.php?city=$1&state=$2&zip=$3 etc… [L]


Sure! I believe I got into this in my tutorial and discuss the limits to the simple method and how to extend to the allowed length of the URI (255 characters).



LoL!! i’m always afraid to post a rewrite question cuz i know you will reply with ‘check out my tutorial’ :slight_smile:

but good stuff… i found it in your tutorial… i’ll give it a try and if have question i post it.

enjoy your weekend.

i tried the following script but have no clue what i means…

if i added it… I’m assuming search/city/state/zip will be added into query string?

what’s the difference between using your example as opposed to doing something like RewriteRule ^/?([a-zA-z0-9_]+)$ search.php?zg=$1
and getting the query string from zg=brooklyn-ny-keyword-keyword. in this case i would have to split my query string.

RewriteRule ^search/([a-z]+)/([a-zA-Z0-9_]+)(/(.))$ $4/?$1=$2 [QSA,N,L]

RewriteCond %{QUERY_STRING} =
RewriteRule ^$ search.php [L]


Until I get another question …

It’s fortunate that my “developing regex” example is using a very similar URI development and the regex coding. Please take a look there as it covers the ORDER sequence of country/state/city (and your subsequent digits and verbiage can be assigned as required.



To answer my own question

a Router is needed for unlimited params

Or could us a based MVC (Controller/Method/Param/Param/Param/Param)
Regex to handle that is

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]