I've made a copy of a Magento folder to set up another domain, swapped the old domain name both in the database (web secure url) and in the filesystem (env.php), and pretty much everywhere I could find it (did a recursive case-insensitive grep for the subdomain name and a search in the database dump) but I'm still getting a 301 redirect to the original website. Where could it be hiding? There are no traces of the old name in the filesystem except some references in the css files and no references to it at all in the database. I've hacked the redirect php files and it seems to occur inside Magento. Here's the trace (url name changed):
string(27) "https://old.webstore.com/"
#1 Magento\Framework\App\Response\Http\Interceptor[Magento\Framework\HTTP\PhpEnvironment\Response]#00000000000002390000000000000000#->setRedirect() called at [generated/code/Magento/Framework/App/Response/Http/Interceptor.php:149]
#2 Magento\Framework\App\Response\Http\Interceptor#00000000000002390000000000000000#->setRedirect() called at [vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php:91]
#3 Magento\Store\App\FrontController\Plugin\RequestPreprocessor#000000000000022f0000000000000000#->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#4 Magento\Framework\App\FrontController\Interceptor#00000000000001750000000000000000#->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php:75]
#5 Magento\PageCache\Model\App\FrontController\BuiltinPlugin#000000000000019f0000000000000000#->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#6 Magento\Framework\App\FrontController\Interceptor#00000000000001750000000000000000#->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#7 Magento\Framework\App\FrontController\Interceptor#00000000000001750000000000000000#->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:23]
#8 Magento\Framework\App\FrontController\Interceptor#00000000000001750000000000000000#->dispatch() called at [vendor/magento/framework/App/Http.php:116]
#9 Magento\Framework\App\Http\Interceptor[Magento\Framework\App\Http]#000000000000009d0000000000000000#->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#10 Magento\Framework\App\Http\Interceptor#000000000000009d0000000000000000#->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#11 Magento\Framework\App\Bootstrap#000000000000000b0000000000000000#->run() called at [pub/index.php:30]
SELECT * FROM core_config_data WHERE path LIKE 'web/%secure/base_url';
app/etc/env.php
. Don't forget to flush Magento cache after any configuration changes.