nystudio107 / retour

DEPRECATED Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website.
Other
168 stars 24 forks source link

Trimming query string when it shouldn't #84

Closed jimmycook closed 7 years ago

jimmycook commented 7 years ago

Using latest master branch

screen shot 2017-09-04 at 17 01 20

This then trims any query string passed to it.

For example I've been using /cookingwithcod?test=true and this is the log output:

2017/09/04 15:59:31 [info] [plugin] A 404 exception occurred in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/RetourPlugin.php (32) 2017/09/04 15:59:31 [info] [plugin] 404 URL: /cookingwithcod?test=true in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/RetourPlugin.php (41) 2017/09/04 15:59:31 [info] [plugin] Cached Redirect hit: in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (128) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (91) 2017/09/04 15:59:32 [info] [plugin] Not handled: /cookingwithcod?test=true in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (254) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (103) 2017/09/04 15:59:32 [info] [plugin] Not handled: /cookingwithcod?test=true in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (254) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (111) 2017/09/04 15:59:32 [info] [plugin] Cached Redirect hit: Array ( [id] => 1253 [redirectSrcUrl] => /cookingwithcod [redirectSrcUrlParsed] => /cookingwithcod [redirectMatchType] => exactmatch [redirectDestUrl] => /recipes/cooking-with-cod [redirectHttpCode] => 301 [hitCount] => 16 [hitLastTime] => 2017-09-04 15:57:48 [locale] => en_gb [associatedElementId] => 0 [dateCreated] => 2017-09-04 15:06:40 [dateUpdated] => 2017-09-04 15:52:19 [uid] => 193f894f-3970-43bf-9a87-fe55f16b77f2 )

in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (128) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (91) 2017/09/04 15:59:32 [info] [plugin] Cached Redirect saved: 1 in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (163) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (94) 2017/09/04 15:59:32 [info] [plugin] [cached] exactmatch result: in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (95) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/RetourPlugin.php (53) 2017/09/04 15:59:32 [info] [plugin] Trimmed 0 from retour_stats table in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (431) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/services/RetourService.php (401) 2017/09/04 15:59:32 [info] [plugin] Redirecting /cookingwithcod?test=true to /recipes/cooking-with-cod in /Users/jimmy/Code/Sites/fishisthedish/craft/app/etc/plugins/BasePlugin.php (65) in /Users/jimmy/Code/Sites/fishisthedish/craft/plugins/retour/RetourPlugin.php (58)

Hope that's enough info, this doesn't seem to be intended behaviour.

khalwat commented 7 years ago

It tries to match both with and without the query string:

                    $redirect = craft()->retour->findRedirectMatch($url);

                    if (isset($redirect)) {
                        craft()->retour->incrementStatistics($url, true);
                        $event->handled = true;
                        RetourPlugin::log("Redirecting " . $url . " to " . $redirect['redirectDestUrl'], LogLevel::Info, false);
                        craft()->request->redirect($redirect['redirectDestUrl'], true, $redirect['redirectHttpCode']);
                    } else {
                        // Now try it without the query string, too, otherwise let Craft handle it
                        $redirect = craft()->retour->findRedirectMatch($noQueryUrl);

                        if (isset($redirect)) {
                            craft()->retour->incrementStatistics($url, true);
                            $event->handled = true;
                            RetourPlugin::log("Redirecting " . $url . " to " . $redirect['redirectDestUrl'], LogLevel::Info, false);
                            craft()->request->redirect($redirect['redirectDestUrl'], true, $redirect['redirectHttpCode']);
                        } else {
                            craft()->retour->incrementStatistics($url, false);
                        }
                    }
jimmycook commented 7 years ago

is there a way to preserve the query string every time? Looking to keep parameters there for tracking reasons.

Thanks

khalwat commented 7 years ago

Yeah you can do that with a RegEx match

cavellblood commented 6 years ago

Is there anyway to preserve the query string with dynamic redirects? Or should these all be converted over to static redirects?