Shaydez
October 24, 2013, 10:17pm
1
Is there a way to have a mod rewrite to make friendly query strings
something.php?city=brooklyn&state=ny&zip=11214&keyword=hi&keyword=another
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]
dklynn
October 26, 2013, 10:06am
2
Shay,
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).
Regards,
DK
LoL!! i’m always afraid to post a rewrite question cuz i know you will reply with ‘check out my tutorial’
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]
dklynn
October 26, 2013, 11:21pm
5
Shay,
Shaydez:
LoL!! i’m always afraid to post a rewrite question cuz i know you will reply with ‘check out my tutorial’
OMG! I’m not allowed to try to protect myself from typing the same info/code repetitively? Yeah, it didn’t work, did it?
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.
Until I get another question …
Shaydez:
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.
The difference is whether you use mod_rewrite to split the key/value pairs or your script (the script has tools to make that easier … but your -'s can be easily misinterpreted).
# Please use the
…
wrapper
RewriteRule ^search/([a-z]+)/([a-zA-Z0-9_]+)(/(.*))*$ $4/?$1=$2 [QSA,N,L]
# Where do you get the name of the key from "something/brooklyn/ny/11214/hi/another full example" ?
RewriteCond %{QUERY_STRING} = # No regex? This only requires "=" in the query string
RewriteRule ^$ search.php [L]
# and ^$ says that the URI is blank (the URL is just the domain).
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.
Regards,
DK
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]