301 перенаправляет для определенных c URL-адресов с помощью Google App Engine (go)? - PullRequest
0 голосов
/ 21 марта 2020

Я использую Google App Engine (go) .. и надеюсь перенаправить https://www.ibikeride.com/scotland/comrie-croft-mountain-bike-trails/amp

на https://www.ibikeride.com/scotland/comrie-croft-mountain-bike-trails

Я посмотрел документацию по движку приложений Google для перенаправлений, но это более чем расплывчато. Я предполагаю, что это перенаправление, настроенное в файле app.yaml под обработчиками.

На самом деле я хочу перенаправить все файлы, оканчивающиеся на "amp", на одну и ту же структуру URL без amp, если есть простой способ сделать это и избежать моего перенаправления более 100 человек.

Для соответствующей информации, вот как мои текущие обработчики выглядят NB (до попытки этого). У меня есть несколько обработчиков для удаления «. html» в конце URL (для определенных c категорий), а также один в конце, чтобы перенаправить все файлы для защиты «https»

Любая помощь ценится

 handlers:

# this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(england/.*\.html)$
  static_files: static/\1
  upload: static/england/.*\.html$

# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(england/.*)$
  static_files: static/\1.html
  upload: static/england/.*\.html$

# this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(scotland/.*\.html)$
  static_files: static/\1
  upload: static/scotland/.*\.html$

# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(scotland/.*)$
  static_files: static/\1.html
  upload: static/scotland/.*\.html$

# this serves your static/some/path/<file>.html asset as /some/path/<file>.html

- url: /(wales/.*\.html)$
  static_files: static/\1
  upload: static/wales/.*\.html$

# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(wales.*)$
  static_files: static/\1.html
  upload: static/wales/.*\.html$

  # this serves your static/some/path/<file>.html asset as /some/path/<file>.html
- url: /(northern-ireland/.*\.html)$
  static_files: static/\1
  upload: static/orthern-ireland/.*\.html$

# this serves your static/some/path/<file>.html asset as /some/path/<file>
- url: /(northern-ireland.*)$
  static_files: static/\1.html
  upload: static/northern-ireland/.*\.html$

#redirect always to https 
- url: /.*
  script: auto
  secure: always
  redirect_http_response_code: 301

1 Ответ

1 голос
/ 24 марта 2020

Поскольку вы используете классификационную часть amp в конце, а не в начале, я бы предложил вам создать небольшой сервис, который перенаправляет автоматически.

Например, в app.yaml:

handlers:
....
- url: /.*/amp
  script: main.go

и код (основной. go):

package main

import (
    "fmt"
    "net/http"
)

type Handler struct{}


func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    uri := r.URL.Path
    length := len(uri)
    newUrl := uri[0:length-3] // Remove trailing amp
    http.Redirect(w, r, newUrl, http.StatusMovedPermanently)
    return
}

func main() {
    handler := new(Handler)
    http.ListenAndServe(":8080", handler)
}
...