Forum Moderators: phranque
...twitter_demo/dummy?oauth_token=BGvrWnAWkA5uTvZViC7CERbBLKGRvZD1oiPPo6BDOA
Below is the Rewrite that I have in the htaccess.
RewriteRule ^twitter_demo/dummy?oauth_token=(.*+)$ twitter_demo/dummy/$1 [NC,L]
I need to pull out the oauth_token and set it to the $1 var. Do you see anything wrong with the syntax? It seems to be having a hard time finding the pattern and setting it. I've tried a multiple different things like, (.*), (.+), (.*+), but none of them seem to work on the string.
Any ideas?
.+ = something.
.*+ = ambiguous, I wouldn't use it.
The main problem is that RewriteRule cannot see query string data.
You need a separate, preceding, RewriteCond to look at the QUERY_STRING value.
This is something covered in the tutorials linked from the forum charter.
Additionally, you use the word 'redirect' in your question and provide code for a 'rewrite' below that. A 'rewrite' is the correct thing to do, but you must be very careful with the terminology. A 'redirect' would be a disaster.
I added the RewriteCond as below,
RewriteCond %{QUERY_STRING} ^oauth_token=(.*)$
RewriteRule ^twitter_demo/dummy /twitter_demo/dummy/%1 [L]
But now it is throwing a 500 internal server error. Could this be due to the RewriteRule reading and writing to the the same dummy method?
If I change the line to,
RewriteRule ^twitter_demo/status /twitter_demo/dummy/%1 [L]
It gives me a 404 error, stating that the page is not there, yet I know it is.
So your pattern will match "twitter_demo/dummy" followed by anything or nothing, because it's not anchored. Also, the original query string will still be present on the rewritten path, so it will match too.
In addition, should additional query parameters be present (by error or malicious intent) in the request, your query string pattern will fail.
All-in-all, based on just what's here in the thread, I'd suggest:
RewriteCond %{QUERY_STRING} ^([^&]*&)*oauth_token=([^&]*)
RewriteRule ^twitter_demo/dummy$ /twitter_demo/dummy/%2? [L]
Jim
from:
RewriteCond %{QUERY_STRING} ^([^&]*&)*oauth_token=([^&]*)
to this:
RewriteCond %{QUERY_STRING} ^([^&]*&)*oauth_token=([^&]*)&next=([^&]*)
correct?
[edited by: jdMorgan at 1:26 am (utc) on Dec. 19, 2009]
[edit reason] Disabled smilies in code. [/edit]
I actually had tried it, along with,
RewriteCond %{QUERY_STRING} ^([^&]*&)*oauth_token=([^&]*)\&next=([^&]*)
and neither of them seemed to have worked. But I just realized the error was something else.
[edited by: jdMorgan at 10:55 pm (utc) on Dec. 21, 2009]
[edit reason] Disabled smilies in code. [/edit]