Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Feature Request: Wildcards in Redirects #92

Closed
jamesward opened this issue Jan 7, 2018 · 8 comments · Fixed by biw/heroku-buildpack-static#2
Closed

Feature Request: Wildcards in Redirects #92

jamesward opened this issue Jan 7, 2018 · 8 comments · Fixed by biw/heroku-buildpack-static#2

Comments

@jamesward
Copy link

Support wildcards in redirects, like:

{
  "redirects": {
    "/foo/**": "/"
  }
}

So that /foo/bar/baz will redirect to /bar/baz and /foo/asdf will redirect to /asdf.

@jamesward jamesward changed the title Feature Request Feature Request: Wildcards in Redirects Jan 7, 2018
@jamesward
Copy link
Author

I think this doesn't work currently because the config generator uses named locations. I think this can be fixed with: jamesward@f0c5550

@jamesward
Copy link
Author

With the change above my static.json can include:

"~ ^/foo/(.*)$": {
  "url": "/$1"
}

@sivakumar-kailasam
Copy link

sivakumar-kailasam commented Feb 21, 2018

@jamesward Wouldn't this be a breaking change for existing users though? Especially since most of us already use the git url for the buildpack. I mention this because I'd love to have wildcard support as well but noticed my named redirects getting borked. May be add a new section just for wildcard redirects?

@jamesward
Copy link
Author

@sivakumar-kailasam Yeah, that is a good point. Probably need some tests to validate non-breakage.

jamesward referenced this issue in jamesward/heroku-buildpack-static May 14, 2018
@mansona
Copy link

mansona commented May 25, 2018

We took a very slightly different approach to this. We also stopped using named locations for redirects because it was impossible for us to set a redirect for /, but it was an "opt-in" situation.

You can see the code here: https://github.com/stonecircle/heroku-buildpack-ember-static/blob/master/scripts/config/templates/nginx.conf.erb#L108 but essentially we allow users to set "force_redirect" to be true and then it will define redirects using regex.

Another way to approach this would be to have each rule define if it wanted to use the regex approach. What are people's thoughts?

@mansona
Copy link

mansona commented Jun 8, 2018

I have extracted the basis for my previous implementation into a PR that captures a more useful API for this functionality: #105

Please let me know if anyone finds this useful 👍

biw added a commit to biw/heroku-buildpack-static that referenced this issue Nov 26, 2018
> Fixes heroku#92
>
> I have implemented an example repo that is using this fork of the buildpack and it is working exactly as expected.
>
> You can see a (silly) index page that explains what is going on here: static-test-mansona.herokuapp.com
>
> Essentially what it allows you to do is to define indvidual rules as regex as you see fit, this way you can make full use of wildcards and domain redirects. Here is an example config:
>
> ```
> {
>  "root": "public_html",
>  "clean_urls": true,
>  "redirects": {
>    "/standard/": {
>      "url": "https://heroku.com",
>      "status": 302
>    },
>    "/magic(.*)": {
>      "url": "https://stonecircle.io$1",
>      "regex": true
>    }
>  }
> } 
> ```
>
> As you can see that if you visit static-test-mansona.herokuapp.com/magic/opensource it will redirect you to stonecircle.io/opensource 👍

 -- @mansona

See https://github.com/heroku/heroku-buildpack-static/pull/105/files
@EloB
Copy link

EloB commented Oct 2, 2019

Why isn't this merged? Seems like a really good feature.

@edmorley
Copy link
Member

edmorley commented Jun 9, 2022

Hi

This buildpack is now deprecated and we are recommending people move the more actively maintained heroku-buildpack-nginx. For migration advice see here.

As such, I'm closing this issue out since we won't be making further changes to this buildpack.

@edmorley edmorley closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants