Forum Moderators: phranque
[edited by: engine at 11:16 am (utc) on Oct 15, 2015]
[edit reason] please use example.com [/edit]
RewriteCond %{QUERY_STRING} param1=([^&]+)¶m2=([^&]+)
RewriteRule ^(index\.php)?$ http://www.example.org/%1/%2? [R=301,L]
That's not the exact rule, of course, but that's the concept. Each capture from the query string becomes % in the target. The ? at the end of the target is what prevents the query from being reappended. RewriteCond %{QUERY_STRING} \bs=([^&])&cat=([^&])
RewriteRule ^index\.php http://example.new/index.php/%1/ ....
Whoops! Where'd the "cornices" come from? Obviously the string "cornices" is not deducible from the string "1", so we need to get more complicated. (?:^|&)but let's not borrow trouble. I do not have access to the old domains hosting as it is parked on the new domain.
I am getting redirected to the home page of that site "http://www.example.new/index.php" rather than to the individual page "http://www.example.new/index.php/products/cornices". The URL that displays in the browser is the original URL
RewriteCond %{HTTP_HOST} example\.old
RewriteCond %{QUERY_STRING} etcetera as before
... and this rule (and all the others for the various values of "cat") has to go before any rules that are specific to the new site.
I would prefer to do a 301 redirect, however from what I have read it cannot handle the encoded characters.
RewriteCond %{HTTP_HOST} example\.old
RewriteRule gizmo http://example.new/foobar [R=301,L]
In your browser, request yes the above code redirected to the new domain/foobar and produced a not found message
fromI forgot to ask if "s" can have values other than "products". I'm assuming it can, in which case the rule looks like this
http://www.example.old/index.php?s=products&cat=1
to
http://example.new/index.php/products/cornices
RewriteCond %{HTTP_HOST} example\.old
RewriteCond %{QUERY_STRING} cat=1
RewriteCond %{QUERY_STRING} \bs=([^&]+)
RewriteRule ^(index\.php)?$ http://example.new/%1/cornices [R=301,L]
This is assuming the possible values of "cat" are never more than one digit. If there's a possibility of "cat=17" or similar, say cat=1\b with word-ending anchor. Conversely, if "products" is the only possible value of "s" (or, at least, the only possible value when cat=1) then you don't need to capture anything; just use the literal text "s=products" without parentheses. RewriteCond %{HTTP_HOST} example\.newUnless something has gotten seriously messed up, this should be "example\.old" And the condition has to be attached to each rule. (Each RewriteRule is an island. Conditions apply only to the current rule.) This is a non-fatal error, because requests aimed at example.new will fail the assorted query-string tests-- but it's more work for the server than the quick-and-brutal hostname test.