Nginx: rewrite to a file without URL changing
up vote
1
down vote
favorite
I have tried many options, but did not find a suitable answer. I can do this in Apache, but I can’t figure out how to do a redirect in Nginx while maintaining the URL
.../s1 changes to .../image.jpg - how to fix it?
location /s
rewrite "/s1" https://example.com/image.jpg last;
nginx
add a comment |
up vote
1
down vote
favorite
I have tried many options, but did not find a suitable answer. I can do this in Apache, but I can’t figure out how to do a redirect in Nginx while maintaining the URL
.../s1 changes to .../image.jpg - how to fix it?
location /s
rewrite "/s1" https://example.com/image.jpg last;
nginx
Try:rewrite ^/s1$ /image.jpg last;
- the first parameter should be a regular expression - and by usinghttps://example.com/
you are turning the rewrite into a redirect.
– Richard Smith
Nov 8 at 17:36
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have tried many options, but did not find a suitable answer. I can do this in Apache, but I can’t figure out how to do a redirect in Nginx while maintaining the URL
.../s1 changes to .../image.jpg - how to fix it?
location /s
rewrite "/s1" https://example.com/image.jpg last;
nginx
I have tried many options, but did not find a suitable answer. I can do this in Apache, but I can’t figure out how to do a redirect in Nginx while maintaining the URL
.../s1 changes to .../image.jpg - how to fix it?
location /s
rewrite "/s1" https://example.com/image.jpg last;
nginx
nginx
edited Nov 8 at 17:26
dmcgrandle
748114
748114
asked Nov 8 at 17:20
noobsaibot
328
328
Try:rewrite ^/s1$ /image.jpg last;
- the first parameter should be a regular expression - and by usinghttps://example.com/
you are turning the rewrite into a redirect.
– Richard Smith
Nov 8 at 17:36
add a comment |
Try:rewrite ^/s1$ /image.jpg last;
- the first parameter should be a regular expression - and by usinghttps://example.com/
you are turning the rewrite into a redirect.
– Richard Smith
Nov 8 at 17:36
Try:
rewrite ^/s1$ /image.jpg last;
- the first parameter should be a regular expression - and by using https://example.com/
you are turning the rewrite into a redirect.– Richard Smith
Nov 8 at 17:36
Try:
rewrite ^/s1$ /image.jpg last;
- the first parameter should be a regular expression - and by using https://example.com/
you are turning the rewrite into a redirect.– Richard Smith
Nov 8 at 17:36
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
A redirect always changes the url, a rewrite keeps it internally.
In this case nginx is turning your rewrite into a redirect, because you specified a different server. You have 2 options:
- If the url you want to rewrite to is local, you should simply remove the
https://example.com
part to make the url relative instead of absolute. - If you really want to mask a different server, then what you need to build is a reverse proxy. Nginx does have features for this.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
A redirect always changes the url, a rewrite keeps it internally.
In this case nginx is turning your rewrite into a redirect, because you specified a different server. You have 2 options:
- If the url you want to rewrite to is local, you should simply remove the
https://example.com
part to make the url relative instead of absolute. - If you really want to mask a different server, then what you need to build is a reverse proxy. Nginx does have features for this.
add a comment |
up vote
0
down vote
accepted
A redirect always changes the url, a rewrite keeps it internally.
In this case nginx is turning your rewrite into a redirect, because you specified a different server. You have 2 options:
- If the url you want to rewrite to is local, you should simply remove the
https://example.com
part to make the url relative instead of absolute. - If you really want to mask a different server, then what you need to build is a reverse proxy. Nginx does have features for this.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
A redirect always changes the url, a rewrite keeps it internally.
In this case nginx is turning your rewrite into a redirect, because you specified a different server. You have 2 options:
- If the url you want to rewrite to is local, you should simply remove the
https://example.com
part to make the url relative instead of absolute. - If you really want to mask a different server, then what you need to build is a reverse proxy. Nginx does have features for this.
A redirect always changes the url, a rewrite keeps it internally.
In this case nginx is turning your rewrite into a redirect, because you specified a different server. You have 2 options:
- If the url you want to rewrite to is local, you should simply remove the
https://example.com
part to make the url relative instead of absolute. - If you really want to mask a different server, then what you need to build is a reverse proxy. Nginx does have features for this.
answered Nov 8 at 17:37
Evert
39.4k1568123
39.4k1568123
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213017%2fnginx-rewrite-to-a-file-without-url-changing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try:
rewrite ^/s1$ /image.jpg last;
- the first parameter should be a regular expression - and by usinghttps://example.com/
you are turning the rewrite into a redirect.– Richard Smith
Nov 8 at 17:36