Redirect url with query string

Moving a site to Wordpress and have a specific old url that I want to redirect to new page with 301

The old page that I want to redirect is
www.mydomain.co./property/region/Brittany/type.php?ss=Brittany&tt=Gites%20Complex&var1=mls&var=type
And I want it to redirect to
www.mydomain.com/property/search/Cotes-dArmor_Finistere_Ille-et-Vilaine_Morbihan/p/p/b/Gites-Complex/l/a/

I think because of some rewrite rules I have added, the old page isn't currently producing a 404
It's redirecting to
www.mydomain/property/region/Brittany/type.php/?ss=Brittany&tt=Gites%20Complex&var1=mls&var=type
The difference is the forward slash after type.php

I'm pretty sure it's some existing rewrite rules I've set up that are causing this. These are
add_rewrite_rule( 'property/region/([^/]+)/([^/]+)/?', 'index.php?&page_id=69695&mls=$matches[1]&pageno=$matches[2]', 'top');
add_rewrite_rule( 'property/region/([^/]+)/?', 'index.php?&page_id=69695&mls=$matches[1]', 'top');

I don't seem to be able to overwrite these rules for this specific url

I've tried
add_rewrite_rule( 'property/region/Brittany/type.php?ss=Brittany&tt=Gites%20Complex&var1=mls&var=type?', 'index.php?&page_id=70318&mls=Cotes-dArmor_Finistere_Ille-et-Vilaine_Morbihan&minp=p&maxp=p&beds=b&type=Gites-Complex&minl=l&area=a', 'top');

I've also tried adding this to top of .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^ss=Brittany&tt=Gites%20Complex&var1=mls&var=type$ [NC]
RewriteRule ^/property/region/Brittany/type.php$ http://www.mydomain.com/property/search/Cotes-dArmor_Finistere_Ille-et-Vilaine_Morbihan/p/p/b/Gites-Complex/l/a/? [R=301,L]
</IfModule>

I'm sure it's something very minor that I've got wrong, but I just can't spot it.
LVL 1
fionafentonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
For your RewriteCond, the '%' character is special, denoting a backreference.  Escape it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^ss=Brittany&tt=Gites\%20Complex&var1=mls&var=type$ [NC]
RewriteRule ^/property/region/Brittany/type.php$ http://www.mydomain.com/property/search/Cotes-dArmor_Finistere_Ille-et-Vilaine_Morbihan/p/p/b/Gites-Complex/l/a/? [R=301,L]
</IfModule>

Open in new window


Also, try to use a code block when posting file contents.  It makes it much easier to read.
fionafentonAuthor Commented:
Unfortunately that hasn't worked. It's still redirecting to www.mydomain/property/region/Brittany/type.php/?ss=Brittany&tt=Gites%20Complex&var1=mls&var=type
It's just adding the forward slash after type.php

I removed all my redirects so that I would get a 404 for the page (leaving in the one for property/search/). I then added this to top of .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^ss=Brittany&tt=Gites\%20Complex&var1=mls&var=type$ [NC]
RewriteRule ^/property/region/Brittany/type.php$ http://www.mydomain.com/property/search/Cotes-dArmor_Finistere_Ille-et-Vilaine_Morbihan/p/p/b/Gites-Complex/l/a/? [R=301,L]
</IfModule>

Open in new window

And I'm still getting a 404. So there must still be still be something wrong with the above code.
Steve BinkCommented:
Light up you rewrite log and post results of a single browse attempt.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

fionafentonAuthor Commented:
I don't have access to create a rewrite log.
Steve BinkCommented:
That makes things much more difficult.

A couple more things you can try:

1) Add the [NC] flag to your RewriteRule.  You have mixed-caps in that rule, so that could have an effect.

2) Remove the RewriteCond entirely and verify the RewriteRule by itself is picking up the request.  If it works, add pieces of the query string test back in one by one, testing for failure each time.  Remember that RewriteCond is not a token parser... it will execute a literal match.  E.g., "&var1=mls&var=type" will not match "&var=type&var1=mls".
fionafentonAuthor Commented:
I'm pretty sure the RewriteRule isn't getting processed up at all. What I think is happening is that my Wordpress add_rewrite_rule is taking precedence. My understanding is that if I place my RewriteRule at the top of the .htaccess file then this would be processed before the Wordpress ones, but this obviously isn't happening.
Steve BinkCommented:
Your initial understanding is 100% correct.  Wordpress does not even have a chance to act until after Apache routes the request, which means finishing the application of any rewrites found in .htaccess files.  

The problem here is a malformed rule, complicated by the fact that you have no log facility for debugging.

Here's one more simple fix you can try.  If this doesn't work, then we get serious:
RewriteCond %{QUERY_STRING} ^ss=Brittany&tt=Gites\%20Complex&var1=mls&var=type$ [NC]
RewriteRule ^/?property/region/Brittany/type.php$ http://www.mydomain.com/property/search/Cotes-dArmor_Finistere_Ille-et-Vilaine_Morbihan/p/p/b/Gites-Complex/l/a/? [R=301,L]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fionafentonAuthor Commented:
It's working!
Thank you so much for all your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.