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

Requesting dynamic client-side redirects #1749

Closed
diazona opened this issue Jul 6, 2017 · 2 comments
Closed

Requesting dynamic client-side redirects #1749

diazona opened this issue Jul 6, 2017 · 2 comments
Labels
feature ⚙️ New feature or request
Milestone

Comments

@diazona
Copy link

diazona commented Jul 6, 2017

I'm making this feature request to consolidate previous requests for dynamic redirects, by which I mean the ability to issue client-side redirects (HTTP 3xx status codes) based on matching the URL to a pattern - presumably a regular expression - not just a fixed string. redir already issues client-side redirects but cannot match a URL pattern, whereas rewrite can match patterns using regular expressions, but doesn't do client-side redirection, so neither of these existing directives are significant.

Background and justification

This has been previously brought up in

Those pages identify several situations in which dynamic redirection would be useful:

  • redirect all URLs with a given file extension, with the new URL depending on the old one
  • redirect all URLs under a directory tree, with the new URL depending on the old one
  • stripping or adding terminal slashes
  • redirecting URLs with single-digit months to have leading zeros

In each case internal rewriting as performed by rewrite is not suitable because it's necessary to signal a change in the page's location to search engines and other visitors.

All of these cases can be addressed with workarounds, but in some cases the workaround is rather impractical, like creating a long list of exact-match redirect rules (1, 2). That wouldn't even work if, say, the destination URL is proxied on to a dynamic backend site where it's not possible to enumerate all valid destinations. (Though in that case one could probably let the backend handle the redirection, but it's not hard to imagine reasons that might be difficult.) So even though it could be argued that dynamic redirection isn't necessary, it would massively simplify the configuration in a wide variety of situation.

Plus, dynamic client-side redirects is something that webmasters typically expect a server to do. Most (all?) other popular web servers include this functionality. I think there are enough cases justifying it that it's worth implementing in Caddy too.

@mholt mholt added the feature ⚙️ New feature or request label Jul 6, 2017
@astei
Copy link

astei commented Jul 6, 2017

I've actually been looking to implement this feature, so I'm going to consider giving this a go.

astei added a commit to astei/caddy that referenced this issue Jul 6, 2017
This adds a new "redirect" directive to the complex rewrite directive. Providing an HTTP response code will force Caddy to issue an HTTP redirect instead of internally rewriting the request.

Fixes caddyserver#1749, caddyserver#726, caddyserver#856
astei added a commit to astei/caddy that referenced this issue Jul 6, 2017
This adds a new "redirect" directive to the complex rewrite directive. Providing an HTTP response code will force Caddy to issue an HTTP redirect instead of internally rewriting the request.

Fixes caddyserver#1749, caddyserver#726, caddyserver#856
@mholt mholt added the in progress 🏃‍♂️ Being actively worked on label Aug 9, 2017
@mholt mholt removed the in progress 🏃‍♂️ Being actively worked on label Feb 16, 2018
@mholt
Copy link
Member

mholt commented May 9, 2019

This is made much easier in Caddy 2.

@mholt mholt closed this as completed May 9, 2019
@mholt mholt added this to the 2.0 milestone May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants