I've just rebuilt a website and have been trying to put in redirects for their old pages which also use index.php, for example:

index.php?option=com_content&view=article&id=4&Itemid=3

I can use the redirect module on sites not hosted on Aegir but these fail with 404s on Aegir. I am using Omega8 so my hands are tied with regards to making any modifications to Aegir (I imagine doing this would be bad practice anyway, much like hacking core).

I've been told by the awesome support at Omega8 that:
"The problem is that we can add such rewrites for any other URI, for almost any .php file, as long as they are not already used in Drupal, but we can't do this for anything which starts with /index.php, because:
1. Nginx doesn't accept duplicate locations.
2. /index.php is an internal only location, which can't be extended."
...and...
"This is something deeply in the Aegir with Nginx safe configuration and we simply can't modify it because the /index.php location is already defined and can't be extended via extra config includes."
...and...
"This would have to be implemented (but I have no idea if they are willing to work on this) on the Aegir Provision level: https://www.drupal.org/project/provision"

So, is this something that anyone is going to want to resolve? Is there anything else I can do?!

I've actually got two website rebuilds with this issue on the go at the moment. I've really no idea about the internals of Aegir or the provision module (I don't need to as I've got Omega8!) and I don't have a local Aegir installation either so I'm sorry, I'm not able to be of any help resolving this. From an SEO perspective it appears as though I will have to take the site off of Aegir and host somewhere else where I can add these redirects, a horribly backwards step for me!

Cheers.

Comments

helmo’s picture

I'm not sure about Nginx, but Apache can do it.

  RewriteCond "%{QUERY_STRING}" "option=com_content&view=article&id=4&Itemid=3"
  RewriteRule ^/index.php$ /node/1? [R,L]

One of the options to add vhost config is on http://community.aegirproject.org/node/73

Another might be: https://www.drupal.org/project/hosting_injections

danwonac’s picture

Thanks for your thoughts helmo. I too thought this would be the solution but my understanding is that this can't work (and indeed doesn't, it was tested) because of the duplicate/non-extendable internal locations factor (I've no idea why).

Perhaps the other suggestions might work but that's not up to me and frankly way beyond me. I know Omega8 watch these issue queues so I'll leave it to them to weigh in if they want to :)

omega8cc’s picture

Scratch that. It is not relevant in this situation, and the only problem is related to /index.php defined as internal only location, as explained in the following comment.

It is not possible for reasons our support already explained. I will try to provide more details, though.

Thanks to very strict handling of .php files execution with explicitly defined locations (which can't be overridden by any config "injection" anyway), we have already prevented all Nginx based Aegir users from many security threats, including some which required Aegir security releases but affected only Apache based systems.

That is why I'm against making it more "open" by removing current restrictions.

Plus, Aegir always forced clean URLs, so something like /index.php?alien=stuff (even as a base for further redirects/rewrites) was never expected to work anyway.

But even if we would remove current restrictions (introduced by popular demand) and allow direct requests to /index.php it would still not provide a way to add such rewrites/redirects, because to make them effective you would still have to be able to add them **inside** already existing location for /index.php, so we would need to develop an extra injection point/method to be able to add rewrites precisely within /index.php location in the default config.

And it goes even worse, because this configuration/location is shared between all vhosts/sites in your Aegir system, so you would need to manage extra, parent pseudo if{} locations to restrict this per site, which is highly discouraged and a messy to manage (and we would never allow this on hosted instances for security reasons).

It is basically a request for removing already tested and saving many people a lot of headaches security restrictions, to get some added complexity and potential security hole, or at least ability to break configuration for all hosted sites, easily.

Not a good idea, in my opinion.

omega8cc’s picture

I just realized that you are trying to use $args in these rewrites, which is not going to work anyway, because you can use literal or regex, but only on the URI, which ends at /index.php so everything following ? is simply ignored.

To correct approach is to add rewrites matching against $args and not $uri

This is something already doable via built-in config extension: https://github.com/omega8cc/boa/blob/master/docs/HINTS.txt

The only missing part would be to make the internal; line optional inside the location = /index.php { }. Otherwise it will throw 404 before it can process rewrites for requests starting with /index.php

Her is an example on how these redirects should be defined:

  if ( $args ~* "^item_id=1000011525" ) {
    rewrite ^ $scheme://$host/node/5? permanent;
  }
  if ( $args ~* "^item_id=1000011526" ) {
    rewrite ^ $scheme://$host/node/6? permanent;
  }
danwonac’s picture

Excellent! It looks like you've already tested this, I am getting redirects rather than 404s now.

Thanks for you help.

  • omega8cc committed df548ea on 6.x-2.x
    Issue #2511772 by danwonac - Nginx: Restore support for legacy rewrites...

  • omega8cc committed 1e5404c on 7.x-3.x
    Issue #2511772 by danwonac - Nginx: Restore support for legacy rewrites...
omega8cc’s picture

Version: 6.x-2.4 » 6.x-2.x-dev
Status: Active » Fixed

We have removed this restriction which affected only BOA users, so /index.php is no longer an internal only location. This is better solution than adding some extra complexity to make it possible. Now rewrites/redirects of this type can be added via already supported extra config includes in BOA.

omega8cc’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

This is in fact for 7.x-3.x, which is the version used in BOA.

danwonac’s picture

Just a quick note to say everything is working perfectly and thanks for your time and effort in providing a solution, really appreciated!

Status: Fixed » Closed (fixed)

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