I have a setup for a couple of small Swedish newspapers, two regional and one national - and domain is a great fit for our new website. :)

My problem is that I have static information pages ("About the company" kind of stuff) in my menu, and with SEO switched on - those URLs are rewritten for all users. Without SEO - there's no problem.

I have tried all imaginable combinations of affiliation settings, and the only way to get the link to stay within the current domain - is to disallow affiliation all other domains.

The sites are entirely in Swedish, but if you'd like to take a look - they are located at http://beta.fria.nu (the main site), http://beta.stockholmsfria.nu (one of the regional papers). The menu in question is the top vertical bar, and the menu item is the one floating to the right ("Om Fria Tidningar") - and two of its subitems.

I had a look at custom_url_rewrite_outbound, but I can't immediately see where this goes wrong. I've also tried intercepting the links at theme level - but the URLs have not yet been rewritten there as far as I can tell, which does seem a bit strange. I have the values recieved by theme_menu_item_link and theme_links dumped at the bottom of the page currently - and none of them contains a FQDN.

Anyway, the misbehaviour disappears if I switch SEO off (which I am reluctant to do). However, the best solution for me would be if I could switch the SEO off for these particular pages (since then the subitems of those menus will become indexed, and some of those are unique for each newspaper - like subscription stuff).

Comments

agentrickard’s picture

Title: Overzealous SEO » Disable SEO on some pages
Category: bug » feature
Status: Active » Postponed (maintainer needs more info)

Well, this is really a "by design" feature. I changed the issue status and title because your request runs counter to the current logic.

By design, the SEO optimization is "greedy" -- it will transform all node links to follow absolute paths to the assigned domain for a node. If you disable strict SEO, you still have the ability to force this behavior on specific paths, using the "Special page requests" form on the module settings page.

I would not call this "misbehavior" -- it is the core design of the module.

What you seem to be after is a way to disable SEO rewrites on specific pages.

You are correct that the behavior is controlled through custom_url_rewrite_outbound(). What you may want to do is copy that function directly into your settings.php file and then edit it. Remove the include call as well. That way updating the module will not interfere with your modifications.

To modify the function as you need, I think that all you need to do is to comment out the final clause in the function.

/*
        // If strict SEO rules are enabled, we set "all affiliate" links to the root domain.
        // Only needed if we are not on the root domain.
        else if ($seo && $_domain['domain_id'] != $root['domain_id']) {
          $absolute = TRUE;
            // In this case, the $base_url cannot have a trailing slash
            $base_url = rtrim($root['path'], '/');
        }
*/

This piece is the logic that rewrites urls for pages assigned to "all affiliates." If you disable it, and assign those menu links to "all affiliates," then you should get the behavior you want. However, this would mean that any node that is assigned to "all affiliates" will be linked to from the current domain. If this is not the behavior you want, then we have to do something else.

In that case, you would need some logic to tell the function to skip the rewrite sequence. Like so:

    // Check to see that this function is installed.
    $skip = FALSE;
    $arg = arg(0);
    if ($arg == 'admin' && ($path == 'domain_access_test_path' || $path == 'domain_access_path_test')) {
      $path = 'yes';
      $skip = TRUE;
    }
    // New logic here.
    if ($arg == 'my_special_path' || $arg = 'my_menu_link") {
      $skip = TRUE;
    }

The logic of that IF statement will vary, depending on how your menu items are structured.

agentrickard’s picture

I took a quick look. Here is the kind of logic I think you need.

    // Check to see that this function is installed.
    $skip = FALSE;
    $arg = arg(0);
    if ($arg == 'admin' && ($path == 'domain_access_test_path' || $path == 'domain_access_path_test')) {
      $path = 'yes';
      $skip = TRUE;
    }
    // New logic here.
    $special_paths = array(
      'omfria/om-fria-tidningar', 
      'omfria/lediga-jobb',
      'omfria/aterforsaljare-ft',
    ); // add more as necessary
    if (in_array($path, $special_paths)) {
      $skip = TRUE;
    }

The 'omfria' part of the path may not be needed, if that is a subdirectory of the install and not a Drupal internal path.

Ibn al-Hazardous’s picture

Thanks for the quick answer(s)! :)

I'm afraid I mixed a bug report and a feature request in one post, mea culpa. The bug is that SEO rewrites URLs even if the user agent is Firefox or Internet Explorer (at least for static nodes in menus, and at least for me - that is what currently happens at the URLs I provided). Should I repost the bug, without mixing it up with a feature request?

Anyway, thanks for the pointers to where I can hack the feature (disabling SEO on some pages) in. I'll get started on it right away! :)

Ibn al-Hazardous’s picture

There, got it to work. :)

But I realize that I made an assumption about how SEO works, that probably isn't valid. I was thinking that SEO only is activated when the user agent is a search engine spider (alternatively, when the user agent isn't a well known browser). Since it appears that isn't so, I suppose that'd be a second feature request. Would anyone else be interested in something like that?

Ibn al-Hazardous’s picture

I just made a quickie - to see if it's feasible to enable SEO for search spiders only. This is what I came up with:

function custom_url_rewrite_outbound(&$path, &$query, &$fragment, &$absolute, &$base_url, $original_path) {
  global $_domain;

  // New code
  static $disable=null;
  if ($disable === null) {
    $disable=true; 
    $se_user_agents = array(
      'Googlebot',
      'msnbot',
      'Slurp',
      'Ask Jeeves',
      // Might wanna add rss-readers?
    );
    
    foreach ($se_user_agents as $match){
      if (preg_match("|".$match."|", $_SERVER['HTTP_USER_AGENT'])){
        $disable=false;
      } 
    } 
  } 
// End of new code, there's a little more at the end of the snippet
  
// If the domain_id is not set, then the Domain module is not active, and we cannot run this function.
  if (isset($_domain['domain_id'])) {
    // Set static variables for the node lookups, to remove redundant queries.
    static $domain_site, $domain, $nodepaths;
    
    // Store the original path for later use.
    $original_path = $path;
    
    // Check to see that this function is installed.
    $skip = FALSE;
    $arg = arg(0);
    if ($arg == 'admin' && ($path == 'domain_access_test_path' || $path == 'domain_access_path_test')) {
      $path = 'yes';
      $skip = TRUE;
    } 

    // New code: This isn't a search spider (might want to make this part configurable)
    if ($disable){
      $skip=TRUE;
    } 

As far as I can see, the problem with my approach is keeping the list of search engine user agents up to date. I guess that would be manageable with a central xml-file checked with cron. OTOH it's not that long between versions on a supported Drupal module.

agentrickard’s picture

Right. The URL rewrite feature happens at the PHP level when the page is being generated, and it doesn't care how the page is being generated.

Now you do have two tangled reports. Let's keep the spider report over at http://drupal.org/node/255711

As for the issue here, did the above code solve your menu problem?

sun’s picture

This is probably a duplicate of #256007: Single Sign-on and SEO

Ibn al-Hazardous’s picture

Yes, the suggested solution works fine. The only change needed was that I had to use the unaliased URLs (node/1234), otherwise it works perfectly. :)

As for this being a duplicate of #256007, I doubt it. We don't use SSO, and probably never will - since our newspapers are distinct products that share some articles. What we really wanna do, is turning on SEO for search spiders only, but I'll keep the rest of the discussion that generates over at http://drupal.org/node/255711 as requested. :)

sun’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Sorry, #7 was based on the code in #1 and #2. Your code in #5 is definitely a completely different topic and probably a new feature.

Marking as duplicate of #256007: Single Sign-on and SEO for now.

agentrickard’s picture

Status: Closed (duplicate) » Postponed

Well, the original issue -- Disable SEO on some pages -- still applies. I don't know that it will ever get coded, but we should keep this around for reference.

Basically, you might have need for a setting that lists pages for which url rewrites should be ignored.

agentrickard’s picture

Status: Postponed » Closed (won't fix)