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:

Comments

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

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

Oh, and this will not hit 1.x.

Issue summary:View changes

Updated issue summary.

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

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

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

Status:Active» Needs review

Please mark patched issues as needs review!

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!

StatusFileSize
new10.58 KB

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.

Status:Patch (to be ported)» Fixed

Pushed as 191766c, thanks.

Status:Fixed» Needs work
StatusFileSize
new91.9 KB
new107.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.

r1r2

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.

<?php
/**
* 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;
}
?>

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

Status:Needs work» Needs review
StatusFileSize
new751 bytes
new1.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.

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...

Status:Fixed» Needs work

This needs to be fixed also for Nginx config.

Ah right, sorry I missed that. :)

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

good. anyone working on a fix for nginx though?

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.

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

Status:Needs work» Fixed

okay, now this is done.

Status:Fixed» Closed (fixed)

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

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

Issue summary:View changes

Updated issue summary.