Forum Moderators: phranque
So, to test or create back-references to query_strings, use mod_rewrite's RewriteCond directive testing the %{QUERY_STRING} variable, in addition to a RewriteRule pattern matching the URL(s) to which that query is attached.
Jim
Your description of a rewrite is exactly backwards. You need a redirect for that action, and then a rewrite in the other direction. Try this way of thinking about things:
You need to link to the new URLs from the pages of your site. It is these links that 'define' URLs.
You then need a rewrite to take that new format URL request, and fetch the content from your pre-exisiting internal dynamic server filepath. The rewrite will not contain a domain name and will end with [L].
You'll also need a redirect to take a direct client request for the old URLs (with parameters included), and redirect to the new URL for that content. That redirect will contain the full domain name in the target URL, and end with [R=301,L].
List them in this order: redirects first, rewrites last.
I have an old jive integrated forum site. I'm replacing it with a new clearspace site. So... if someone has favorited www.example.com/app/forum.jspa?category=119 I want that request to get forwarded to www.newexample.com/app2/newcategoryname. I don't need to do any URL cleanup, or masking, or anything. Just fwd requests from old, to new and have the URL change in the window. No proxies, no anything fancy :)
I had something like this, but it didn't work the way I expected
RewriteRule http://www.example.com/library/kbcategory.jspa?categoryID=660 [newexample.com...] [R=301,L]
What I ended up getting was redirected to [newexample.com...]
I suspect this is because of the ?, but I could be wrong.
You need a RewriteCond for each of HOST_NAME and QUERY_STRING if you need to look at those.
A redirect will contain the full domain name in the target URL, and end with [R=301,L].
You can clear the query string from being re-appended to the target URL by placing a question mark on the end of the target URL.
From your description, you need a redirect from old URL to new URL. It doesn't look like you need any sort of rewrite as you have moved to a new system.
I'm not too familiar with RewriteConditions, so forgive me if I've completely butchered the concept :) I am using RewriteRule because that's what we've used for all of our redirects, even to other sites(or at least that's what others have used).
So I need a pair of these for everything I'm going to do. Correct?
What old URLs+querystrings need to be redirected?
What URLs+querystrings might look like those, but should not be redirected?
What are the defining characteristics that distiguish these two sets of URLs+querystrings?
For example, if *all* URLs requested with *any* query string containing "categoryID=" should be redirected, then simply removing "660" from your current rewritecond pattern would do that.
Jim
So for example, ID=22 redirects to /blah/blah2/blah3 but ID=23 might redirect to /blah/page/index.html and ID=24 redirects to /welcome.html
I was able to do some clever find/replaces and generate the 100 or so lines I needed to accomplish this, and implemented on my test server and all seems to be working as expected.
End the URL with a trailing slash, and let your DirectoryIndex directive find and serve up the correct content for this.
Make sure you force the www in each redirect, so that you don't create a non-www vs. www duplicate content issue on the new site.