views:

42

answers:

3

I'm trying to redirect a URL that looks like

'accommodation/destination.php?code=108459&destination=Yang+Chum+Noi'

The regex I'm using:

(^accommodation/destination\.php\?code=([0-9]+)&destination=([^/]+)$)

...works fine in my regex tester but when I use it in the .htaccess file it doesn't work.

Am I missing something here?

+1  A: 

You don't need to escape slashes but the point. And RewriteRule don't care about caracters after interrogation point, so you have to use QSA flag.

But this redirection seems weird, how do you use this regexp in your htaccess ??

MatTheCat
Yes a couple of unnecessary escapes, I'll take them out when it's working. I'm redirecting to another URL using the captured code
Chaoley
You forget QSA, it's not the way of a htaccess redirection which serve to hide GET parameters..!
MatTheCat
Actually this redirection is from an old URL that uses GET parameters to a new one that does not, and is handled below the current line. I'm checking the documentation for QSA now but is doesn't seem applicable as I'm not passing the query string.
Chaoley
MatTheCat
No, there's at least 150 of these old URLs in Google's index, it has to use a regex
Chaoley
Isn't just GET parameters which change ?
MatTheCat
OK, that would be a solution but the htaccess is now working, thanks for your help with the QSA flag
Chaoley
+1  A: 
bazmegakapa
It should, but it isn't on my servers, development or production, other regexs are working fine on both
Chaoley
That looks like it should work but it's not, it's driving me crazy
Chaoley
Can you paste the whole rule as it is in your htaccess?
bazmegakapa
Chaoley
You should change this to the RewriteCond version, because RewriteRule will not check the query string.
bazmegakapa
Also, don't you want to use $2 in your URL?
bazmegakapa
Chaoley
Sorry, that is the one I'm using, no the first capture is the numeric ID
Chaoley
I don't get it... If RewriteCond and RewriteRule is in a separate line, I'm out of ideas :). Maybe I'm not drunk enough yet.
bazmegakapa
Do you have http:// before example.com?
bazmegakapa
Yes, but the problem is that htaccess isn't matching the regex, I'll have a drink too, see if it helps :)
Chaoley
Ok, it's now redirecting but appending the query string
Chaoley
It was a typo in my htaccess file, all fixed now, no need for more thinking fluid :)
Chaoley
No worries, I would have gotten drunk anyways :).
bazmegakapa
+1  A: 

Done, with the help of both MatTheCat and bazmegakapa I got it to work, the {QUERY_STRING} solution was OK after I fixed my own typo, and after removing the QSA flag using the solution here http://www.google.com/support/forum/p/Webmasters/thread?tid=55432a1ab73cdf5a&hl=en it is now working, thanks again to both of you for your help.

Chaoley