Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Add routes.yaml {all} option for route templates. #4795

Merged
merged 16 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _includes/cloud/note-pro-missing-self-service-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{: .bs-callout .bs-callout-info}
On Pro projects, we recommend updating YAML configuration files in an Integration environment and testing the changes before pushing the updates to Staging and Production environments. If you discover that configuration changes are not applied to Staging and Production sites after you redeploy and do not see any related error messages in the log, submit a [Support ticket](http://support.magento.com) that describes the attempted configuration changes. Include any updated YAML configuration files in the ticket.
2 changes: 2 additions & 0 deletions _includes/cloud/note-route-all-placeholder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{: .bs-callout-info}
The following route configuration examples use route templates with placeholders. The `{default}` placeholder represents the default domain configured for your site. If your project has multiple domains, use the `{all}` placeholder instead to configure routing for the default domain and all aliases. See [Configure routes]({{ page.baseurl }}/cloud/project/project-conf-files_routes.html).
56 changes: 41 additions & 15 deletions guides/v2.1/cloud/project/project-conf-files_routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ functional_areas:
- Setup
---

{{site.data.var.ee}} processes an incoming URL using a *route*. The `routes.yaml` file—located at `.magento/routes.yaml` in your project—defines routes for the Integration environment. The deploy script uses values defined in the configuration files in the `.magento` directory and deletes the directory after deployment. Your local workspace is not affected.
{{site.data.var.ee}} processes an incoming URL using a *route*. The `routes.yaml` file—located at `.magento/routes.yaml` in your project—defines routes for the Integration, Staging, and Production environments. The deploy script uses values defined in the configuration files in the `.magento` directory and deletes the directory after deployment. Your local workspace is not affected.

{% include cloud/note-pro-using-yaml-support.md %}
{% include cloud/note-pro-missing-self-service-options.md %}

The following is the default `routes.yaml` file:

Expand All @@ -32,23 +32,49 @@ magento-cloud environment:routes
+-------------------+----------+---------------+
```

## Route templates
The `routes.yaml` file is a list of templated routes and their configurations. You can use the following placeholders in a route template:

The `routes.yaml` file is a list of templated routes and their configurations. A route template looks similar to this: `http://www.{default}/` or `https://{default}/blog`, where `{default}` is the qualified domain name configured for the project. For example, the routes for `example.com` domain resolve to the following:
- `{default}` represents the qualified domain name configured as the default for the project. For example, if you have a project with the default domain `example.com`, the route templates `http://www.{default}/` and `https://{default}/blog` resolve to the following URLs in a production environment:

- `http://www.example.com/`
- `https://example.com/blog`
```text
http://www.example.com/

{{site.data.var.ee}} also generates URLs for every active environment, so you can test that system. In a test system, `{default}` is replaced with the following:
http://www.example.com/blog
```

```
In a non-production branch, the `{default}` placeholder resolves to the project ID and environment ID.

- `{all}` represents all the domain names configured for the project. For example, if you have a project with `example.com` and `example1.com` domains, the route templates `http://www.{all}/` and `https://{all}/blog` resolve to routes for all domains in the project:

```text
http://www.example.com/

http://www.example.com/blog

http://www.example1.com/

http://www.example1.com/blog
```

The `{all}` placeholder is useful for projects configured for multiple domains. In a non-production branch `{all}` is replaced with the project ID and environment ID for each domain.

If a project does not have any domains configured which is common during development, the `{all}` placeholder behaves in the same way as the `{default}` placeholder.

{{site.data.var.ee}} also generates URLs for every active environment, so you can test that system. In a test system, `{default}` is replaced with the following domain name:

```text
[branch]-[project-id].[region].magentosite.cloud
```

For example, if the project ID is `mswy7hzcuhcjw` on a branch called `refactorcss` hosted in the `us` cluster, the domains are:
For example, the `refactorcss` branch for the `mswy7hzcuhcjw` project hosted in the `us` cluster has the following the domains:

- `http://www-refactorcss-mswy7hzcuhcjw.us.magentosite.cloud/`
- `https://refactorcss-mswy7hzcuhcjw.us.magentosite.cloud/blog`
```text
http://www-refactorcss-mswy7hzcuhcjw.us.magentosite.cloud/
```

```text
https://refactorcss-mswy7hzcuhcjw.us.magentosite.cloud/blog
```

<!-- {{site.data.var.ece}} also supports [multiple applications]({{ page.baseurl }}/cloud/project/project-conf-multi.html) per project. Each project has a single `routes.yaml` file that defines which request is routed to which application. -->

Expand Down Expand Up @@ -96,10 +122,10 @@ In the first sample, the server responds directly to a request of the form `http
## Wildcard routes
{{site.data.var.ece}} supports wildcard routes, so you can map multiple subdomains to the same application. This works for [redirect](https://glossary.magento.com/redirect) and upstream routes. You prefix the route with an asterisk (\*). For example, the following routes to the same application:

- `*.example.com`
- `www.example.com`
- `blog.example.com`
- `us.example.com`
- `*.example.com`
- `www.example.com`
- `blog.example.com`
- `us.example.com`

This functions as a catch-all domain in a live environment.

Expand Down
2 changes: 2 additions & 0 deletions guides/v2.1/cloud/project/project-routes-more-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ functional_areas:

{{site.data.var.ee}} enables you to use caching in your environment. If you disable caching, {{site.data.var.ee}} directly serves the files.

{% include cloud/note-route-all-placeholder.md %}

## Set up caching {#cloud-cache-setup}

Enable caching in your Magento application's `.magento/routes.yaml` as follows:
Expand Down
178 changes: 69 additions & 109 deletions guides/v2.1/cloud/project/project-routes-more-redir.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Managing redirection rules is a common requirement for web applications, especia

If the redirection methods discussed in this topic do not work for you, you can use caching headers to do the same thing.

{% include cloud/note-route-all-placeholder.md %}

## Whole-route redirects {#cloud-route-whole}

Using whole-route redirects, you can define very basic routes using the `routes.yaml` file. For example, you can redirect from a naked domain to a `www` subdomain as follows:
Using whole-route redirects, you can define simple routes using the `routes.yaml` file. For example, you can redirect from a naked domain to a `www` subdomain as follows:

```yaml
http://{default}/:
Expand All @@ -22,8 +24,7 @@ http://{default}/:

## Partial redirects {#cloud-route-partial}

In the [`.magento/routes.yaml`]({{ page.baseurl }}/cloud/project/project-conf-files_routes.html) file you can also add partial [redirect](https://glossary.magento.com/redirect) rules
to existing routes:
In the [`.magento/routes.yaml`]({{ page.baseurl }}/cloud/project/project-conf-files_routes.html) file you can also add partial redirect rules to existing routes:

```yaml
http://{default}/:
Expand All @@ -34,114 +35,73 @@ http://{default}/:
"/regexp/(.*)/matching": { "to": "http://example.com/$1", regexp: true }
```

This format is more rich and works with any type of route, including routes served directly by the application.
You can use partial redirects with any type of route, including routes served directly by the application.

Two keys are available under `redirects`:

- `expires`: Optional, the duration that the redirect is cached.
- **`expires`**—Optional, the duration that the redirect is cached.
Examples of valid values include `3600s`, `1d`, `2w`, `3m`.

- `paths`: The paths to apply the redirects to.

The following defines each rule under `paths`:

- A key that describes the expression to match against the request path
- A value object describing both the destination to redirect to with detail on how to handle the redirection.

The value object is defined with the following keys:

- [`to`](#cloud-route-partial-to)
- [`regexp`](#cloud-route-partial-regexp)
- [`prefix`](#cloud-route-partial-prefix)
- [`append_suffix`](#cloud-route-partial-append)
- [`code`](#cloud-route-partial-code)

### `to` {#cloud-route-partial-to}

Required, a partial (`"/destination"` or `"//destination"`) or full URL (`"http://example.com/"`).

### `regexp` {#cloud-route-partial-regexp}

Optional, defaults to `false`. Specifies whether the path key should be interpreted asa PCRE regular expression.

{% collapsible Click to show/hide content %}

In the following example, a request to `http://example.com/regexp/a/b/c/match` redirects to `http://example.com/a/b/c`:

```yaml
http://{default}/:
type: upstream
redirects:
paths:
"/regexp/(.*)/match":
to: "http://example.com/$1"
regexp: true
```

{% endcollapsible %}

### `prefix` {#cloud-route-partial-prefix}
Specifies whether or not to redirect both the path and all its children or just the path itself. Defaults to `true`, but is not supported if `regexp` is `true`.

{% collapsible Click to show/hide content %}

For example,

```yaml
http://{default}/:
type: upstream
redirects:
paths:
"/from":
to: "http://{default}/to"
prefix: true
```

In the preceding example, if `prefix` is set to `true`, `/from` redirects to `/to` and `/from/another/path` will redirect to `/to/another/path`

If `prefix` is set to `false`, `/from` triggers a redirect, but `/from/another/path` does not.

{% endcollapsible %}

### `append_suffix` {#cloud-route-partial-append}
Determines if the suffix is carried over with the redirect. Defaults to `true`, but not supported if `regexp` is `true` *or* if `prefix` is `false`.

{% collapsible Click to show/hide content %}

For example,

```yaml
http://{default}/:
type: upstream
redirects:
paths:
"/from":
to: "http://{default}/to"
append_suffix: false
```

The preceding example results in `/from/path/suffix` redirecting to just `/to`.

If `append_suffix` is set to its default value of `true`, `/from/path/suffix` redirects to `/to/path/suffix`.

{% endcollapsible %}

### `code` {#cloud-route-partial-code}

Specifies the HTTP status code. Valid status codes are [`301` (Moved Permanently)](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2), [`302`](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3), [`307`](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8), and [`308`](https://tools.ietf.org/html/rfc7238). Defaults to `302`.

### `expires` {#cloud-route-partial-expires}

Optional, the duration to cache redirect. Defaults to the `expires` value defined directly under the `redirects` key, but at this level you can fine-tune the expiration of individual partial redirects:

```yaml
http://{default}/:
type: upstream
redirects:
expires: 1d
paths:
"/from": { "to": "http://example.com/" }
"/here": { "to": "http://example.com/there", "expires": "2w" }
```

In the preceding example, redirects from `/from` expire in one day, but redirects from `/here` expire in two weeks.
- **`paths`**—The paths to apply the redirects to.

The `paths` property includes a _key_ that describes the expression to match against the request path
and a _value_ object that describes both the destination to redirect to with detail on how to handle the redirection. The value object is defined with the following keys:

- **`to`**— Required, a partial (`"/destination"` or `"//destination"`) or full URL (`"http://example.com/"`).
- **`regexp`**— Optional, defaults to `false`. Specifies whether the path key should be interpreted as a PCRE regular expression.

In the following example, a request to `http://example.com/regexp/a/b/c/match` redirects to `http://example.com/a/b/c`:

```yaml
http://{default}/:
type: upstream
redirects:
paths:
"/regexp/(.*)/match":
to: "http://example.com/$1"
regexp: true
```

- **`prefix`**—Specifies whether the redirect applies to both the path and all its children, or just the path itself. Defaults to `true`. This value is not supported if `regexp` is `true`.

In the following example, if `prefix` is set to `true`, `/from` redirects to `/to` and `/from/another/path` redirects to `/to/another/path`. If `prefix` is set to `false`, `/from` triggers a redirect, but `/from/another/path` does not.

```yaml
http://{default}/:
type: upstream
redirects:
paths:
"/from":
to: "http://{default}/to"
prefix: true
```

- **`append_suffix`**—Determines if the suffix is carried over with the redirect. Defaults to `true`, but not supported if `regexp` is `true` *or* if `prefix` is `false`.

In the following example, `/from/path/suffix` redirects to just `/to`. If `append_suffix` is set to its default value of `true`, `/from/path/suffix` redirects to `/to/path/suffix`.

```yaml
http://{default}/:
type: upstream
redirects:
paths:
"/from":
to: "http://{default}/to"
append_suffix: false
```

- **`code`**—Specifies the HTTP status code. Valid status codes are [`301` (Moved Permanently)](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2), [`302`](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3), [`307`](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8), and [`308`](https://tools.ietf.org/html/rfc7238). Defaults to `302`.

- **`expires`**—Optional, the duration to cache redirect. Defaults to the `expires` value defined directly under the `redirects` key, but at this level you can fine-tune the expiration of individual partial redirects.

In the following example, redirects from `/from` expire in one day, but redirects from `/here` expire in two weeks.

```yaml
http://{default}/:
type: upstream
redirects:
expires: 1d
paths:
"/from": { "to": "http://example.com/" }
"/here": { "to": "http://example.com/there", "expires": "2w" }
```
4 changes: 2 additions & 2 deletions guides/v2.1/cloud/project/project-routes-more-ssi.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ functional_areas:
- Setup
---

[Server side includes](http://httpd.apache.org/docs/current/howto/ssi.html){:target="_site"} (SSI) are directives in [HTML](https://glossary.magento.com/html) pages that get evaluated on the server while the pages are being rendered. Use of [server side](https://glossary.magento.com/server-side) includes enables you to add dynamically generated content to an existing HTML page without having to serve the entire page.
[Server side includes](http://nginx.org/en/docs/http/ngx_http_ssi_module.html){:target="_site"} (SSI) are directives in [HTML](https://glossary.magento.com/html) pages that get evaluated on the server while the pages are being rendered. Use of [server side](https://glossary.magento.com/server-side) includes enables you to add dynamically generated content to an existing HTML page without having to serve the entire page.

More information about [nginx SSI](http://nginx.org/en/docs/http/ngx_http_ssi_module.html).
{% include cloud/note-route-all-placeholder.md %}

You can activate or deactivate SSI on a per-route basis in your
`.magento/routes.yaml`; for example:
Expand Down