Forum Moderators: phranque

Message Too Old, No Replies

Another dynamic URL endless loop problem

         

dilbert

8:55 pm on Mar 15, 2009 (gmt 0)

10+ Year Member



Hello,
There have been many discussions about this topic, and I apologize for adding to it.
I am completely stumped on why I cannot get this to work.
This is what I originally had in my .htaccess
With this I am getting an endless loop in the browser.

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]

g1smd

9:25 pm on Mar 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Looking only at QUERY_STRING results in an endless loop, as the rewritten pointer matches the input pattern of the redirect. You need to examine THE_REQUEST and use that to determine if the redirect should fire.

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.

dilbert

9:42 pm on Mar 15, 2009 (gmt 0)

10+ Year Member



I don't know why this will not work. I have cleared the cache, and I have tried two other browsers. Still no luck?

jdMorgan

9:57 pm on Mar 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would be very helpful to have several valid "/results.php" test URL-paths posted here -- both some that should be redirected, and some that should not (please specify which), and as different from each other as possible.

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

dilbert

10:31 pm on Mar 15, 2009 (gmt 0)

10+ Year Member



The devil is in the details...

I found the error in my script. Stupid me.
Thank you both so much for the help. I don't know if I would have ever worked this out without the resources of this site, and of course your help.
Thanks again.