I'm creating an migration from Typo3 to drupal and part of this involves creating redirect paths per node.
Typo3 news items have ghastly urls, that look something like http://server.com/menu/news/news-single/?tx_ttnews%5Bpointer%5D=3&tx_ttnews%5Btt_news%5D=2523&tx_ttnews%5BbackPid%5D=13&cHash=cb598dc81775331968be88f9dc974c90, but in fact most of the query string can be safely ignored and we just use http://server.com/menu/news/news-single/?tx_ttnews%5Btt_news%5D=2523.
So I want to redirect from menu/news/news-single/?tx_ttnews%5Btt_news%5D=2523 to node/12345, however I'm running into problems with those percent symbols in the original path. Redirect module is escaping them and is therefore creating entries that look like menu/news/news-single?tx_ttnews%255Btt_news%255D=882. I get a 404 if I enter the original path, and a redirect if I enter the escaped path.
So, the obvious solution is to un-escape the original path before entering it into redirect mode, right?
This means http://server.com/menu/news/news-single/?tx_ttnews%5Btt_news%5D=2523 becomes http://server.com/menu/news/news-single/?tx_ttnews[tt_news]=2523. And when I enter this and then view the list of urls in the UI I see urls that look like http://server.com/menu/news/news-single/?tx_ttnews%5Btt_news%5D=2523, just how I want them to be. Yay, right? But clicking on these URLs gives me a 404 and entering the URL with the square brackets also gives me a 404.
So, for some reason, the unescaped url seems to not work at all.
What gives? How can I work around this?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | redirect-problem-with-url-escaped-characters-1447460-8-D7.patch | 1.16 KB | zestagio |
| #1 | redirect.patch | 517 bytes | torrance123 |
Comments
Comment #1
torrance123 commentedPlease see attached patch.
The issue here is that the incoming url which is decoded in
redirect_init()usesdrupal_get_query_parameters(), whereas the url passed in using the provided UI (or, in my case, via a migration) is decoded inredirect_parse_urlusingdrupal_get_query_array().The difference is that
drupal_get_query_parameters()uses the$_GETarray. This array automagically decodes query parameters that look like array keys, such asvar[one]=one&var[two]=two&three=three, as nested arrays, eg.array('var' => array('one' => 'one', 'two' => 'two'), 'three' => 'three').On the other hand,
drupal_get_query_array()will decode the previous query string simply asarray('var[one]' => 'one', 'var[two]' => 'two', 'three' => 'three'). That is, the square brackets aren't treated specially at all, and simply form part of the array key strings.The attached patch standardises on the latter behaviour (simply because it is easier to do) and uses the
$_SERVER['QUERY_STRING']superglobal as its source, rather than$_GET.Comment #2
torrance123 commentedComment #3
Jarviss commentedI tried to save page?keys=test after patching last dev version of Redirect 2012-May-16, it didn't save it, it saved: page
May you help me with this?
Comment #4
archimedes commentedJust came across this exact same issue on a site. Can't test the patch (trying to get a quick fix in place on production server). Looks like there's no movement on this?
Comment #5
jebeze_alexander commentedUsing 7.x-1.0-beta4 and I encountered a similar problem when creating redirects programmatically via a Rule. I call the redirect_save function, and the url source is encoded when saved and produces a 404 when followed.
project_detail.asp?id=4787 becomes.... project_detail.asp%3Fid%3D4787
Curiously, the issue is "resolved" if I open the Redirect manually for editing in the admin dashboard and then save it without making any changes.
Comment #6
firewaller commentedThat's because the redirect save function stores URL parameters as options instead of as a redirect string:
Example: project_detail.asp?id=4787
Comment #7
pere orgaLikely the same issue than in #1817764: Does not work with more than 2 query parameters
Comment #8
zestagio commentedComment #9
chris matthews commentedComment #10
wylbur commentedClosing this as Outdated as Drupal 7 is EOL.