Forum Moderators: phranque
RewriteEngine on
RewriteCond %{QUERY_STRING} ^Search=([^/]+)
RewriteRule ^results\.php /search-results/%1? [R=301,L]
RewriteRule ^search-results/([^/]+) /results.php?Search=$1 [L]
When I pull off the $1 on the last RewriteRule (as below) the redirect occurs but my search results are not being filtered which returns all the results in the database.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^Search=([^/]+)
RewriteRule ^results\.php /search-results/%1? [R=301,L]
RewriteRule ^search-results/([^/]+) /results.php?Search= [L]
Upon going over the many threads on this topic in the forums, I then used this, but the redirect is not working.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /results\.php\?Search=([^\ ]*)\ HTTP/
RewriteRule ^results\.php$ http://www.example.com/search-results/%1/? [R=301,L]
RewriteRule ^search-results/([^/]+) /results.php?Search=$1 [L]
I am really having trouble with this, any help, advice would be GREATLY appreciated.
[edited by: jdMorgan at 9:59 pm (utc) on Mar. 15, 2009]
[edit reason] Fixed-up the formatting [/edit]
The latter code should be fine, except for one caveat. You are redirecting to a URL that includes a trailing slash. I initially thought that your rewrite will take the trailing slash of that URL and copy it into the parameter. I guess that "keyword/" does not match any database entries. I see now that I misread it, but in any case I would not use a trailing slash in your URL.
I would also urge you to use all lower case in your URLs. Did you flush your browser cache? If not, your browser has cached the redirect pointing to itself and is reusing that.
Note that the target URL of the redirect should contain the domain name, and end [R=301,L] and the rewrite should end with [L]. You do have that correct here, but it is a common error seen elsewhere.
For example, you say that your search results are not being filtered, but without seeing what a "filter" query string URL looks like, it's impossible for us to tell why the filter is being dropped/lost/corrupted/mis-interpreted, etc. So what does a filtered URL-path/query look like, and what does an unfiltered one look like? And if you have multiple query string parameters, how do they "map" to the static/SEO-friendly URL? Are some always present and others optional? Is the order fixed and unchanging?
With mod_rewrite and regular-expressions patterns, the devil is in the details...
Jim