I have a drupal website using taxonomy. Now google indexed the taxonomy paths like: http://mysite.com/term/5865.
Now most of the taxonomy pages should not be accessable, and I want to remove the path, but I can't find how to do it开发者_JAVA技巧 anywhere.
Does anyone have an idea how to do this ?
Thanks in advance.
Create a module called kill_taxonomy and then add the following code to the kill_taxonomy.module file
<?php
/**
* Implementation of hook_menu_alter.
*/
function kill_taxonomy_menu_alter(&$items) {
unset($items['taxonomy/term/%']);
}
?>
Enable the module.
You can disable all by removing the menu item with hook_menu_alter
. The path you want to disable is taxonomy/term/%term
.
Another option is too add a custom access callback to that menu item. Then you can control which terms are open and which are restricted.
All of this should happen in a custom module.
A third option is to use views or panels to overwrite the standard taxonomy page and add some checks / access restriction to filter out unwanted terms.
This seems to be the only thread I could find regarding this issue. Having Drupal's auto-generated taxonomy/term paths available for users and google to find & index isn't always desireable. So how do you hide or disable these paths?
In addition to adding taxonomy/term/ to robots.txt, I tried Bryan's solution to unset $items['taxonomy/term/%'] and it works.
HOWEVER, there's a big GOTCHA to be aware of - If you use Advanced Forums, the RSS feeds for the Forum Categories will stop working. That is bad.
My guess is because Forums uses Taxonomy Vocab Terms for the forum categories, and it seems the RSS feed uses the $items['taxonomy/term/%'] array to generate the feed.
My alternative solution:
I already use URL Alter Module to define custom_url_rewrite_inbound(), so I simply added this condition:
//If path is taxonomy/term/% we force 404
if (preg_match("/^taxonomy\/term\/([0-9]+)(\/.*)?$/i", $path)) {
header("HTTP/1.0 404 Not Found");
die();
}
To use Drupal's default 404 handling, I added:
require_once './includes/bootstrap.inc';
and replaced header("HTTP/1.0 404 Not Found") with:
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_not_found();
Now my site successfully 404s any request for taxonomy/term/%, AND RSS feeds still work. Hopefully this helps someone else having this issue.
If anyone should like to use Qyx's URL Alter solution, they might also like to include whitespace (\s
) characters in their URL matching code, as shown below:
if (preg_match("/^taxonomy\/term\/([0-9\s]+)(\/.*)?$/i", $path))
This prevents urls that call multiple vocabularies from resolving, like taxonomy/term/1 2 3
精彩评论