Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Enforce main domain for environment #17

Closed
sjelfull opened this issue Jun 9, 2016 · 9 comments
Closed

Request: Enforce main domain for environment #17

sjelfull opened this issue Jun 9, 2016 · 9 comments
Assignees

Comments

@sjelfull
Copy link

sjelfull commented Jun 9, 2016

I would love a way to enforce a main domain for an environment where you have multiple domains connected, eg. domain.com and www.domain.com.

Before, I handled this in .htaccess, but I feel that this requires a unnecessary performance hit, however small.

Do you think this would be something that fits within the realm of Patrol?

I'm currently using Hearty to handle environments.

@selvinortiz
Copy link
Owner

I've considered that and I think it does fall within the scope of what could be handled via Patrol.

You mentioned a performance hit and I think that if you can handle it at the server level or even .htaccess, you should. However, Patrol was created out of necessity and for convenience, either because on a shared host you don't have as much freedom or because it makes it easier to enforce rules during development. So, I think I'd like to explore your feature request and try add it when I get the chance;)

@selvinortiz selvinortiz self-assigned this Jun 9, 2016
@selvinortiz
Copy link
Owner

@sjelfull What UI/options do you think this feature should include?

Should it just allow you to select www or Naked Domain enforcement?

@sjelfull
Copy link
Author

I guess this is as much out of convenience as out of care for the performance.

I think you should be able to define what your main domain is, if that's what you you mean by Naked Domain.

The use case I have in mind at the moment is a site where we used a temp. subdomain provided by the host while we were preparing to launch.

After launch, the site is still available from the subdomain, and some of the staff of the client is still using domain. That leads to some instances where it leaks into search results and cache.

I would like a easy way to enforce it, so that it doesn't matter if not all do as instructed.

@selvinortiz
Copy link
Owner

@sjelfull So, let me see if I understand this right. Please correct me if I'm wrong.

You might have a local domain like local.dev and a temporary domain during development as your staging domain, something like temp.domain.com for example.

Your production will be domain.com when you go live but temp.domain.com will remain available for people/admins/bots to access. So, what you want is to be able to force everyone to domain.com instead of temp.domain.com.

I've decided to make this a feature, so if you can just add clarification on your use case, that will be really helpful.

@sjelfull
Copy link
Author

Thanks, that's exactly what i'm after.

@selvinortiz
Copy link
Owner

@sjelfull Here is what I'm thinking...

To add a new setting called primaryDomain that can only be set through config/general.php.

If primaryDomain is set to a non-empty string (like local.dev or temp.domain.com) and the current domain does not match, we redirect to that domain.

That would mean that if you have a multi-environment config set up, you could:

return [
  // all
   '*' => [
    'patrol' => [
      'primaryDomain' => 'domain.com'
    ],
  ],
  // local
  '.dev' => [
    'patrol' => [
      'primaryDomain' => '' // or local.dev
    ],
  ],
];

This would work independently from SSL of course. Thoughts?

selvinortiz added a commit that referenced this issue Jul 14, 2016
- Adds support for enforcing primary domain as outlined in issue #17
- Adds support for blocking all users and admins as outlined in issue #19
- Adds `primaryDomain` as an optional config
- Adds `authorizedUsers` as an optional config
- Updates releases and README
@selvinortiz
Copy link
Owner

@sjelfull I've gone ahead and implemented this feature. Would you be able to test things out and provide some feedback? I'd like to clean up or fix any small bugs (if any) before cutting an official release.

All you have to do is updated your config file with something like this:

return [
  // all
   '*' => [
    'patrol' => [
      'primaryDomain' => 'domain.com'
    ],
  ],
  // local
  '.dev' => [
    'patrol' => [
      'primaryDomain' => '*'
    ],
  ],
];

@sjelfull
Copy link
Author

Looks great. I'm on holidays currently, so probably won't be able to test it out before the 25th.

@selvinortiz
Copy link
Owner

@sjelfull Ok, release https://github.com/selvinortiz/craft.patrol/releases/tag/v1.4.1 should do what you want:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants