Forum Moderators: phranque

Message Too Old, No Replies

Rewritemap and request_uri conflict

         

winglian

7:25 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



I have the following redirect code within my virtualhost directive


RewriteMap oldlinks txt:/var/www/sitedir/.htoldlinks
RewriteCond %{REQUEST_URI}!=""
RewriteCond ${oldlinks:%{REQUEST_URI}¦NOT-FOUND}!=NOT-FOUND
RewriteRule ^.* ${oldlinks:%{REQUEST_URI}} [R=301,L]

and in .htoldlinks i have


/index.cfm?query1=text1 /newdir/newpage1.html
/index.cfm?query1=text2 /newdir/newpage2.html
/anotherpage.cfm?query1=text1 /newdir/newpage3.html
etc...

I have old links from other sites taht are no longer maintained under the same URI. I know the old URI's and where they need to go. However, the rewrite doesn't match any of the requests at all.

in the rtewrite log file i get


init rewrite engine with requested uri /index.cfm
applying pattern '^.*' to uri '/index.cfm'
RewriteCond: input='/index.cfm' pattern='!=""' => matched
cache lookup FAILED, forcing new map lookup
map lookup FAILED: map=oldlinks[txt] key=/index.cfm
RewriteCond: input='NOT-FOUND' pattern='!=NOT-FOUND' => not-matched

indicating that the REQUEST URI is not using the query string too, although it should.
If I add the line to my .htoldlinks file


/index.cfm /newdir/newpage1.html

it will forward to the page for any of the other uri's qith a query string... Any ideas?

Thanks again
Wing

jdMorgan

9:29 pm on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A query string is not part of a URI. Rather, it is a set of parameters to be passed to the resource at the specified URI. Try using %{QUERY_STRING} to extract and test the query string.

Jim

winglian

10:49 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Thanks jim!

I changed my httpd.conf to reflect this and it now works. here's what I have now


RewriteCond %{QUERY_STRING}!=""
RewriteCond %{REQUEST_URI}!=""
RewriteCond ${oldlinks:%{REQUEST_URI}?%{QUERY_STRING}¦NOT-FOUND}!=NOT-FOUND
RewriteRule ^.* ${oldlinks:%{REQUEST_URI}?%{QUERY_STRING}} [R=301,L]

however, I am getting forwarded to


/newdir/newpage1.html?query1=text1

rather than simply

/newdir/newpage1.html

Any ideas on how to blank out the query string?

winglian

11:00 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Never mind, figured it out


RewriteCond %{QUERY_STRING}!=""
RewriteCond %{REQUEST_URI}!=""
RewriteCond ${oldlinks:%{REQUEST_URI}?%{QUERY_STRING}¦NOT-FOUND}!=NOT-FOUND
RewriteRule ^.* ${oldlinks:%{REQUEST_URI}?%{QUERY_STRING}}? [R=301,L]

Just add a "?" after the redirect!

Wing