0

I have a long table of legacy site URLs (Drupal 6 site) and the new URLs they should redirect to on the new site (Drupal 8). The list is too long to make this an .htaccess fix, and too irregular for an easy rule.

I tried simply inserting the rows into the url_alias table and have found that they don't work unless I find them in the URL Aliases admin page, edit them and save them. I guess this means that the redirects are stored somewhere else as well as that table. Clearing the cache manually didn't seem to help.

I can't think of a way to do what I need with the various path / redirect modules I've found so far (though I'm really open to trying) and most of the code samples out there are D6 or D7. Is there a way (as a one-off) that I can get Drupal to re-read the entire url_alias table and make them proper redirects? Or is there another way to get all the redirects in place? Any help much appreciated!

0

For storing aliases use Drupal\Core\Path\AliasStorage:

\Drupal::service('path.alias_storage')->save($source, $alias, $langcode);

But it should be no problem, if you inserted the rows by hand. Check, if all source paths and aliases have a leading '/'. And that langcode is set to a language like 'en' or 'und' for undefined.

Then clear the cache. It is enough to invalidate the cache tag 'route_match':

drush ev '\Drupal\Core\Cache\Cache::invalidateTags(['route_match'])'
  • Think there may have been done browser-level caching going on too, as clearing the cache initially didn't resolve the issue, but later did. Only other change was that I installed the redirect module: possibly that cleared the relevant internal cache? Either way, thanks. – almcnicoll Sep 19 '16 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.