I wrote a way to redirect to a main url of choice, rather than the main site url. In the process of writing this functionality, I realized that I may not actually need this functionality, I found that aegir has "automatic" aliases, and that I just have to change my process to get Aegir to do what I want it to do.

I'm posting this code here in case anyone finds it useful, or thinks this might also be a good idea to have this functionality. Essentially it just gives you another field next to the aliases to type in the url that you want your site redirecting to, and defaults to the main site url.

Note from the Aegir maintainers:

This issue overlaps with:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anarcat’s picture

Before this is implemented, I would like to see this get in: #815190: Allow for both redirects and aliases.

anarcat’s picture

Version: 6.x-1.9 » 6.x-2.x-dev

Oh, and this will not hit 1.x.

Steven Jones’s picture

Issue summary: View changes

Updated issue summary.

Jon Pugh’s picture

I've rebuilt the site alias form to use single textfields, with a "Add More" Ajax button, and added a select list to choose the "redirection target".

I realized that I could use the {hosting_site_alias}.redirection column to store the desired target URI.

The attached patches includes an update hook to change the schema of redirect column to varchar, and handles sites.php, and the vhost file.

It works with the automatic domains as well.

I built this on 1.x to start, but if this has potential to get in, will rewrite it to work with 2.x. I am not sure why this feature has to wait for #815190: Allow for both redirects and aliases

Thoughts?

screenshot

Jon Pugh’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev

Marking for 6.x-1.x-dev for now.

anarcat’s picture

Status: Active » Needs review

Please mark patched issues as needs review!

anarcat’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)

I like this. The interface is better and is a good way to move forward towards #815190: Allow for both redirects and aliases.. We'd just need a "redirect" flag per alias then...

Please port to 2.x, this will not land in 1.x. Thanks for the great work!

helmo’s picture

I've spent some time on this. Testen on 6.x-2.x

* style clean up

It needs more attention, but here's an intermediate result as I'm out of time today.

anarcat’s picture

Status: Patch (to be ported) » Fixed

Pushed as 191766c, thanks.

omega8cc’s picture

Status: Fixed » Needs work
FileSize
91.9 KB
107.32 KB

When "Generate www.domain.com alias automatically" and "Generate domain.com alias automatically" options are enabled, and the main site name is foo.com, it allows you to choose www.foo.com as a "Redirection Target", while in fact in the vhost foo.com is the target still.

r1

r2

Steven Jones’s picture

Priority: Normal » Major

There's another serious issue with what's been committed here too. The update functions depend on the hook_schema implementation so the update functions are not fixed. We need to pull the portion of the hook_schema we want out, and put in the update function.

/**
 * Alter the redirection field to a varchar
 */
function hosting_alias_update_3() {
  $ret = array();
  $schema = hosting_alias_schema();
  $spec = $schema['hosting_site_alias']['fields']['redirection'];
  db_change_field($ret, 'hosting_site_alias', 'redirection', 'redirection', $spec);
  return $ret;
}
ergonlogic’s picture

Also, isn't the convention to call the function something like hosting_alias_update_620x() ?

helmo’s picture

Status: Needs work » Needs review
FileSize
751 bytes
1.77 KB

@Steven Jones: the patch here fixes that.

@ergonlogic: Yes that's the convention, but the older update hooks in that file had the same bad pattern. However I think we should still start doing it right from here one.

When "Generate www.domain.com alias automatically" and "Generate domain.com alias automatically" options are enabled, and the main site name is foo.com, it allows you to choose www.foo.com as a "Redirection Target", while in fact in the vhost foo.com is the target still.

I'm not sure about the Nginx part, but it seems that we 'lost' the provision part of this patch. Here's a reroll.

The http/Provision/Config/Nginx/vhost.tpl.php core seems to only do redirects when $ssl_redirection is true.

anarcat’s picture

Status: Needs review » Fixed

let's see if those patches finish this off properly - my bad for both missing the provision patch and the weird schema anti-pattern.

thanks for the reroll helmo.

edit: sorry - i forgot to give attribution...

omega8cc’s picture

Status: Fixed » Needs work

This needs to be fixed also for Nginx config.

anarcat’s picture

Ah right, sorry I missed that. :)

helmo’s picture

I saw a notice as the result of the redirect code.... fixed in http://drupalcode.org/project/hostmaster.git/commit/46e3498

anarcat’s picture

good. anyone working on a fix for nginx though?

anarcat’s picture

i fixed it for nginx. we have found that there are weird checks in the code for apache which ergonlogic will remove and detail some more, so I am keeping this open for now.

anarcat’s picture

actually, scratch that, it still doesn't work. graah.

anarcat’s picture

Status: Needs work » Fixed

okay, now this is done.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

helmo’s picture

For reference, I've posted a small follow-up: #2010064: Extra update hook to fix hosting_site_alias table content

helmo’s picture

Issue summary: View changes

Updated issue summary.

  • Commit 46e3498 on 6.x-2.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by helmo:
    Issue #1681904 by helmo: Fix a notice on node/add/site
    
  • Commit 5323b6b on 6.x-2.x, 7.x-3.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by anarcat:
    Issue #1681904 by Jon Pugh, helmo: Added Ability to configure a url to...

  • Commit 46e3498 on 6.x-2.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by helmo:
    Issue #1681904 by helmo: Fix a notice on node/add/site
    
  • Commit 5323b6b on 6.x-2.x, 7.x-3.x, dev-588728-views-integration, dev-1403208-new_roles, dev-helmo-3.x by anarcat:
    Issue #1681904 by Jon Pugh, helmo: Added Ability to configure a url to...