It will be handy to allow other modules disable the Global Redirect on certain paths or to have an "Ignore paths" field in the settings.

I have an use case now for that: we are building site where part of the nodes are shown in the premium content section of the site as well as in the public section. So we had to implement our own aliases for private content (premium content isnt indexed by SEO bots so having multiple aliases doesnt matter).

We want to use Global Redirect for the public area. However when we enable the module, we are getting redirected from the premium content area to the public area - to the primary URL aliases of the nodes.

Comments

wojtha’s picture

Status: Active » Needs review
StatusFileSize
new4.01 KB

The following patch adds "Ignore paths" setting to the module settings and adds hook hook_globalredirect_active_path().

Example ignore path:

premium/*

Example hook_globalredirect_active_path() implementation:

/**
 * Implements hook_globalredirect_active_path().
 *
 * Tell global redirect to skip premium/* paths.
 */
function example_globalredirect_active_path($path) {
  if (strpos($path, 'premium/') === 0) {
    return FALSE;
  }
}
wojtha’s picture

Hmm, might be it will be better to provide hook_globalredirect_active_path_alter() instead of hook_globalredirect_active_path(). What do you think?

Status: Needs review » Needs work

The last submitted patch, 1438584-1_globalredirect_active_path.patch, failed testing.

wizonesolutions’s picture

I think the first hook makes more sense. Global Redirect's sole purpose is to redirect to a canonical alias; altering that behavior doesn't make sense. hook_url_inbound/outbound_alter do that job fine.

webkomplize’s picture

Status: Needs work » Needs review
rp7’s picture

Going to follow this one.

A temporary, but not so clean, fix for this might be:

function mymodule_init() {
  $path = request_path();
  if ($path == 'my/special/path') {
    $_POST['globalredirect'] = FALSE;
  }
}

This works because globalredirect only works on pages where $_POST is empty (see _globalredirect_is_active()). If there is other code (outside globalredirect) checking if $_POST is empty, you'll have to account for this though. You'll also need to make sure your mymodule_init runs before globalredirect_init.

A new hook would be awesome.

nicholasthompson’s picture

I very much like the look of this. Nice work!

Suggestions:

  1. Could/should we pass the $alias out to the hook too? Saves other modules doing to the lookup if we've already done it...
  2. Should we pass the "lowercase" version or the original?
  3. Instead of $function, could we use module_invoke?

Apart from that, I'd say this is pretty close to RTBC..

make77’s picture

Is there any news about implementing the "Ignore paths" setting for the next release ?

stefan.r’s picture

Re-roll against 7.x-1.x git

stefan.r’s picture

StatusFileSize
new3.97 KB
stefan.r’s picture

Including feedback from #7.

1. Passing $alias as well.
2. At the moment this depends on whether case_sensitive_urls is enabled so it's neither. Thinking we should pass lowercase paths anyway to prevent any issues. Only drawback of that is that we can't say, /some/path should not redirect while /Some/PATH should but that seems like a very rare edge case anyway.
3. using module_invoke().

stefan.r’s picture

This one passes the lowercase version of both the path and the alias.

jun’s picture

Issue summary: View changes

Any chance this could be committed? Quite useful in my case to ignore a example.com/api path which holds a REST API that doesn't like 301s...

tyler.frankenstein’s picture

Status: Needs review » Reviewed & tested by the community

#12 allows me to ignore all calls to my RESTful API (via the Services module and an endpoint path), e.g.

http://example.com/api/*

Nicely done!

caspervoogt’s picture

Works well. Please commit

anybody’s picture

Great work, do you have a time plan when this will be commited? IT's RTBC since 3 month!

ekes’s picture

+1 - also using to avoid /api (giving the hook also enables doing this in the config code with a simpler, than regex, strpos).

thomas.frobieter’s picture

It would be great if you could commit this sooooon as your time allows (:

Clemens Sahs’s picture

Works great for me, too.

merge it

Seven_Six_Two’s picture

Is this going to make it in to a release any time soon?

nsciacca’s picture

I used the patch from #12 so I could write a custom "hook_globalredirect_active_path", but it was throwing a warning for $alias not existing. I moved some of the lines that defined the alias to outside the if statement process ignore paths so it doesn't throw the warning. Should still work.

markpavlitski’s picture

Status: Reviewed & tested by the community » Needs review

Marking as needs review for patch in #21.

stefan.r’s picture

StatusFileSize
new987 bytes

seems OK to me

tyler.frankenstein’s picture

@stefan.r, what's your latest attachment for?

markpavlitski’s picture

Status: Needs review » Reviewed & tested by the community

@stefan.r Thanks for the interdiff, looks good to me too and does fix the $alias warning. Marking back as RTBC.

mausolos’s picture

Hi, it's been 8 months as RTBC, is there a schedule for pushing this out sometime? :)

alexkb’s picture

I've just tried this patch for a different use case: disabling globalredirect for a particular page in Drupal that has an embedded angular application with html5mode toggled on. It seemed to work great, thanks!

oleksiy’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new479 bytes
new4.04 KB

Thanks for the patch. It's very useful in my case.
I use hook_globalredirect_active_path($path, $alias) to exclude some pages from global redirect. However, when I requested a page using page alias in $path and $alias variables I got the same value for both variables (requested alias). So I can't limit pages by system path. Also my site is multilingual and I get the path\alias with attached language prefix in the hook.

In the previous patch the request_path() function is used to get the path which will be used for ignore list. I propose to use current_path() function instead. Then we can get system path of the requested page and retrieve an alias if it exists and they will be without language prefix

webadpro’s picture

Id have to agree with Oleksiy, that using current_path() could probably be more useful than request_path().

Patch still works great.

vincenzodb’s picture

Patch to 7.x-1.5 version

dripa’s picture

#30 worked, thanks!

jimmynash’s picture

#30 worked for me as well.

tyler.frankenstein’s picture

Status: Needs review » Reviewed & tested by the community
ankitnigam30’s picture

#30 worked great for me as well.But this is not added in 7.x-1.5 version.
when this will be commited in next release ?

jlongbottom’s picture

#30 is working for me

I actually need to ignore all pages for a certain entity type, so I had to get creative with the wildcards. If there was not any static text in my entity's URL pattern, I would not have been able to use this patch for my use case.

So its just an idea, but it would be great for this to work per entity or bundle instead of using paths.

ruchirashree’s picture

This is working as expected. This is currently not in the stable release version 7.x-1.5. It will be great to have this in current stable release. @blueminds, request you to please take it forward.

jamesdevware’s picture

StatusFileSize
new4.47 KB
new783 bytes

A slight modification to _globalredirect_is_active_path() which ensures that $path is always the internal path if one exists. Without this globalredirect_active_path can end up in a situation where $path is actually an alias.

Patch and interdiff attached (rolled against 7.x-1.5, patch does not currently apply cleanly against dev).

@jlongbottom this patch should help you to match by internal path either using pattern or hook_globalredirect_active_path as the internal path will now be checked.

jamesdevware’s picture

StatusFileSize
new4.6 KB
new1.57 KB

I realised that my previous patch would mean that you couldn't match based on the request_path.

New patch allows for matching by internal path as well as the alias / request path.

interdiff is attached against #30 again please ignore #37.

jamesdevware’s picture

StatusFileSize
new5.35 KB
new3 KB

Previous patches were not working when using multilingual based on path prefix.

New patch includes path sanitisation to remove the language prefix ensuring that patterns will match across all languages.

tennist’s picture

Patch from 39 works for me. Can we get this committed in the next stable release.

fgjohnson@lojoh.ca’s picture

Interesting,
We use Deployment between an Authoring server and Production server.
Deploy fails with Global Redirect turned on.

Where do I enter the paths to ignore?
Or Maybe I don't.

This looks great!

Thanks

thomwilhelm’s picture

Looks like this missed the latest release 7.x-1.6

fgjohnson@lojoh.ca’s picture

Yes it did.
And the patch #39 doesn't apply.

fgjohnson@lojoh.ca’s picture

We are running behind a varnish server.

Adding these "paths to ignore" doesn't work.
I assume it's because the base_url in settings.php is the live varnish URL...
Any idea's?

Adding user/* and admin/*

production.site.com is the drupal site...
varnish.site.com is the varnish/public URL.

Once enabled ALL attempts to get to /user just redirect to varnish.site.com .

Thanks

fgjohnson@lojoh.ca’s picture

Last hunk of patch in #39 doesn't apply to 7.x-1.6.

fgjohnson@lojoh.ca’s picture

This patch is for 7.x-1.6.
Why did it fail testing? Because testing is against -dev?

patching file globalredirect.admin.inc
Hunk #1 succeeded at 112 with fuzz 2 (offset 8 lines).
Hunk #2 succeeded at 159 (offset 8 lines).
patching file globalredirect.module
Hunk #1 succeeded at 326 (offset 35 lines).
Hunk #2 succeeded at 401 (offset 35 lines).
Hunk #3 succeeded at 498 (offset 35 lines).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 46: 1438584-46_globalredirect_active_path_0.patch, failed testing. View results