3

I'm using drupal 7 in combination with path auto. I imported nodes of a specific content type using the feed importer, but the url alias is not set correctly.

My problem is, that i can not use the bulk update for content paths, because there is other content, that was migrated manually and that uses non generic url-aliases.

Is there a way to trigger the bulk alias update for a specific content type?

4 Answers 4

6
  • To update URL for Existing Contents You could go to admin/content
  • In Update Options, You can choose Update URL alias after filtering a specific content type

enter image description here

3
  • 3
    Just for everyone else' knowledge, I think the "Update Options" drop down menu shown in the screenshot above, is provided by Views Bulk Operations module (VBO): drupal.org/node/1326928 (it wasn't mentioned entirely in the question or answer). Feb 20, 2017 at 13:46
  • This action is in Drupal 8/9 (in the Action dropdown) at admin/content. It is provided by Pathauto.
    – mlncn
    Apr 9, 2021 at 13:52
  • In D8+ this won't update existing aliases. SQL posted below if it helps anyone.
    – Darren
    Aug 11, 2023 at 13:01
1

In the settings you can chose what updating needs to do if there already is an alias. Under 'Update action' select 'Do nothing. Leave the old alias intact'. Then do a bulck update.

2
  • Thanks for your answer. But that will not work for me because the nodes already have an existing alias, but it was not set correctly (the pattern was not used).
    – sgoelz
    Jan 9, 2015 at 15:03
  • After searching the web for solutions i think, that VBO is the best way to do this
    – sgoelz
    Jan 9, 2015 at 15:04
0

If you're comfortable using SQL, you can do the bulk operation against the database without involving Drupal.

I'd recommend testing the query against a slave, staging or non-production instance of the database to verify the results first, just to be safe:

SELECT alias FROM node
JOIN url_alias
ON CONCAT('node/', node.nid) = url_alias.source
WHERE node.type= 'machine_name';

After you've carefully reviewed the query to verify the results, perform the actual delete:

DELETE url_alias FROM node
JOIN url_alias
ON CONCAT('node/', node.nid) = url_alias.source
WHERE node.type = 'machine_name';

If you don't have access to MySQL database or Drush, you can perform the operation by using a custom Views Bulk Operation or by using Drush:

$ drush sql-query "DELETE url_alias FROM node [...]"

0

If anyone is looking for Drupal 8 version of this SQL it's a bit messy. We had a content type called web_site which had /content/.... as the URL alias. We needed this to be /website/.... The machine name of the content type in question is 'web_site'. See query below:-

update path_alias pa
set alias = concat('/website/',substring_index(substring_index(pa.alias,'/',-1),'/',1))
where pa.path like '/node/%' 
and substring_index(substring_index(pa.path,'/',-1),'/',1) 
in (select nid from node where type = 'web_site');

NOte: checking the existing path contains /node/% ensures we don't update aliases for users, files, etc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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