nginx: Multiple cross-domain 301 redirects with different page addressesnginx rewrite for an url with parametersBlank Page: wordpress on nginx+php-fpmCan not change nginx 1.2.5 default websiteDomino SSL 301 redirect with www and non wwwnginx 302 redirect only naked IPnon www to www domain?Why rewrite(nginx) redirects with 301 code?CodeIgniter nginx rewrite rules for i8ln URL'sConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsWhy Nginx calls for invalid certificate in non-existent subdomains just to redirect to 404?Nginx reverse proxy to many local servers + webserver duty
Can a black dragonborn's acid breath weapon destroy objects?
Does an ice chest packed full of frozen food need ice?
If you had a giant cutting disc 60 miles diameter and rotated it 1000 rps, would the edge be traveling faster than light?
What is wrong with this proof that symmetric matrices commute?
Inconsistent behavior of compiler optimization of unused string
When 2-pentene reacts with HBr, what will be the major product?
How to tell your grandparent to not come to fetch you with their car?
The eyes have it
How to officially communicate to a non-responsive colleague?
Why doesn't Adrian Toomes give up Spider-Man's identity?
How can I most clearly write a homebrew item that affects the ground below its radius after the initial explosion it creates?
At what point in time did Dumbledore ask Snape for this favor?
What does the term "railed" mean in signal processing?
Which comes first? Multiple Imputation, Splitting into train/test, or Standardization/Normalization
How to chain Python function calls so the behaviour is as follows
My coworkers think I had a long honeymoon. Actually I was diagnosed with cancer. How do I talk about it?
Do any instruments not produce overtones?
Why was the Sega Genesis marketed as a 16-bit console?
Interview not reimboursed if offer is made but not accepted
Smooth switching between 12 V batteries, with a toggle switch
What can I, as a user, do about offensive reviews in App Store?
How to project 3d image in the planes xy, xz, yz?
What's the name of this light airplane?
Passing multiple files through stdin (over ssh)
nginx: Multiple cross-domain 301 redirects with different page addresses
nginx rewrite for an url with parametersBlank Page: wordpress on nginx+php-fpmCan not change nginx 1.2.5 default websiteDomino SSL 301 redirect with www and non wwwnginx 302 redirect only naked IPnon www to www domain?Why rewrite(nginx) redirects with 301 code?CodeIgniter nginx rewrite rules for i8ln URL'sConfigure NGINX : How to handle 500 Error on upstream itself, While Nginx handle other 5xx errorsWhy Nginx calls for invalid certificate in non-existent subdomains just to redirect to 404?Nginx reverse proxy to many local servers + webserver duty
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:
http
tohttps
- Different domain
- Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address
Here are two old pages from the old domain:
Portfolio:
http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting
Services:
http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting
Here are two new pages from the new domain:
Services:
https://dcturano.com/services/
https://www.dcturano.com/services/
Portfolio:
https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/
EDIT: This is my nginx.conf file as it currently stands.
server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;
server_name dcturano.com www.dcturano.com;
if ($scheme = http)
return 301 https://$server_name$request_uri;
nginx http redirect https 301-redirect
add a comment |
I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:
http
tohttps
- Different domain
- Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address
Here are two old pages from the old domain:
Portfolio:
http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting
Services:
http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting
Here are two new pages from the new domain:
Services:
https://dcturano.com/services/
https://www.dcturano.com/services/
Portfolio:
https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/
EDIT: This is my nginx.conf file as it currently stands.
server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;
server_name dcturano.com www.dcturano.com;
if ($scheme = http)
return 301 https://$server_name$request_uri;
nginx http redirect https 301-redirect
Possible duplicate of this
– wurtel
Nov 12 '14 at 10:04
Not a duplicate of that question. Also, updated the OP to be more specific.
– eclipsis
Nov 13 '14 at 3:07
add a comment |
I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:
http
tohttps
- Different domain
- Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address
Here are two old pages from the old domain:
Portfolio:
http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting
Services:
http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting
Here are two new pages from the new domain:
Services:
https://dcturano.com/services/
https://www.dcturano.com/services/
Portfolio:
https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/
EDIT: This is my nginx.conf file as it currently stands.
server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;
server_name dcturano.com www.dcturano.com;
if ($scheme = http)
return 301 https://$server_name$request_uri;
nginx http redirect https 301-redirect
I'm moving my old site over to a new domain, and with that new domain comes new naming conventions. I'm trying to figure out what would be the simplest way of accomplishing the following for roughly 8 different pages:
http
tohttps
- Different domain
- Redirect (1) old www and (2) old non-www addresses, plus (3) new non-www address to new www address
Here are two old pages from the old domain:
Portfolio:
http://dcturanoinc.com/?dct=portfolio_expediting
http://www.dcturanoinc.com/?dct=portfolio_expediting
Services:
http://dcturanoinc.com/?dct=services_expediting
http://www.dcturanoinc.com/?dct=services_expediting
Here are two new pages from the new domain:
Services:
https://dcturano.com/services/
https://www.dcturano.com/services/
Portfolio:
https://dcturano.com/portfolio/
https://www.dcturano.com/portfolio/
EDIT: This is my nginx.conf file as it currently stands.
server {
listen 80;
listen [::]:80;
listen 443 default_server ssl;
server_name dcturano.com www.dcturano.com;
if ($scheme = http)
return 301 https://$server_name$request_uri;
nginx http redirect https 301-redirect
nginx http redirect https 301-redirect
edited Nov 13 '14 at 3:07
eclipsis
asked Nov 12 '14 at 1:53
eclipsiseclipsis
223129
223129
Possible duplicate of this
– wurtel
Nov 12 '14 at 10:04
Not a duplicate of that question. Also, updated the OP to be more specific.
– eclipsis
Nov 13 '14 at 3:07
add a comment |
Possible duplicate of this
– wurtel
Nov 12 '14 at 10:04
Not a duplicate of that question. Also, updated the OP to be more specific.
– eclipsis
Nov 13 '14 at 3:07
Possible duplicate of this
– wurtel
Nov 12 '14 at 10:04
Possible duplicate of this
– wurtel
Nov 12 '14 at 10:04
Not a duplicate of that question. Also, updated the OP to be more specific.
– eclipsis
Nov 13 '14 at 3:07
Not a duplicate of that question. Also, updated the OP to be more specific.
– eclipsis
Nov 13 '14 at 3:07
add a comment |
1 Answer
1
active
oldest
votes
1. HTTP -> HTTPS
To automate detection of HTTP vs HTTPS, I would use 2 separate server
blocks:
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect to HTTPS
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
# Serve content
Redirect will be done through the use of return 301
rather than using rewrite
, which is discouraged when avoidable.
2. www.domain -> domain
Now to redirect www to non-www, I would use a map
, avoiding to use if
:
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
then use $new_host
in combination with return 301
3. ?dct=portfolio_ -> ?dct=services_
Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if
.
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
4. All-in-one example
http
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
server
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$new_host/?dct=$new_arg_dct;
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
if ($new_host != $host)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
if ($new_arg_dct != $arg_dct)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...]
redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.
As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map
(or use if
if you know what you are doing) to rewrite the $args
variable, ending up with a rewritten construction ready to be sent to the redirection URL.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2fserverfault.com%2fquestions%2f643677%2fnginx-multiple-cross-domain-301-redirects-with-different-page-addresses%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
1. HTTP -> HTTPS
To automate detection of HTTP vs HTTPS, I would use 2 separate server
blocks:
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect to HTTPS
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
# Serve content
Redirect will be done through the use of return 301
rather than using rewrite
, which is discouraged when avoidable.
2. www.domain -> domain
Now to redirect www to non-www, I would use a map
, avoiding to use if
:
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
then use $new_host
in combination with return 301
3. ?dct=portfolio_ -> ?dct=services_
Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if
.
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
4. All-in-one example
http
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
server
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$new_host/?dct=$new_arg_dct;
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
if ($new_host != $host)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
if ($new_arg_dct != $arg_dct)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...]
redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.
As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map
(or use if
if you know what you are doing) to rewrite the $args
variable, ending up with a rewritten construction ready to be sent to the redirection URL.
add a comment |
1. HTTP -> HTTPS
To automate detection of HTTP vs HTTPS, I would use 2 separate server
blocks:
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect to HTTPS
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
# Serve content
Redirect will be done through the use of return 301
rather than using rewrite
, which is discouraged when avoidable.
2. www.domain -> domain
Now to redirect www to non-www, I would use a map
, avoiding to use if
:
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
then use $new_host
in combination with return 301
3. ?dct=portfolio_ -> ?dct=services_
Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if
.
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
4. All-in-one example
http
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
server
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$new_host/?dct=$new_arg_dct;
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
if ($new_host != $host)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
if ($new_arg_dct != $arg_dct)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...]
redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.
As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map
(or use if
if you know what you are doing) to rewrite the $args
variable, ending up with a rewritten construction ready to be sent to the redirection URL.
add a comment |
1. HTTP -> HTTPS
To automate detection of HTTP vs HTTPS, I would use 2 separate server
blocks:
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect to HTTPS
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
# Serve content
Redirect will be done through the use of return 301
rather than using rewrite
, which is discouraged when avoidable.
2. www.domain -> domain
Now to redirect www to non-www, I would use a map
, avoiding to use if
:
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
then use $new_host
in combination with return 301
3. ?dct=portfolio_ -> ?dct=services_
Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if
.
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
4. All-in-one example
http
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
server
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$new_host/?dct=$new_arg_dct;
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
if ($new_host != $host)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
if ($new_arg_dct != $arg_dct)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...]
redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.
As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map
(or use if
if you know what you are doing) to rewrite the $args
variable, ending up with a rewritten construction ready to be sent to the redirection URL.
1. HTTP -> HTTPS
To automate detection of HTTP vs HTTPS, I would use 2 separate server
blocks:
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect to HTTPS
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
# Serve content
Redirect will be done through the use of return 301
rather than using rewrite
, which is discouraged when avoidable.
2. www.domain -> domain
Now to redirect www to non-www, I would use a map
, avoiding to use if
:
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
then use $new_host
in combination with return 301
3. ?dct=portfolio_ -> ?dct=services_
Finally, to redirect old domains to new ones, it is the kind of arguments filtering explained on the link provided by @wurtel, although I would once again use a map instead of if
.
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
4. All-in-one example
http
map $host $new_host
"~*^www.(?<domain>.+)$" $domain;
default $host;
map $arg_dct $new_arg_dct
"~*^portfolio_(?<dct>.+)$" services_$dct;
default $arg_dct;
server
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$new_host/?dct=$new_arg_dct;
server
listen 443 default_server ssl;
listen [::]:443 default_server ssl;
if ($new_host != $host)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
if ($new_arg_dct != $arg_dct)
# Used $scheme to show you its existence
return 301 $scheme://$new_host/?dct=$new_arg_dct;
As you noticed, the use of seperate servers is not really necessary here, as a simple return 301 https://[...]
redirect would have been sufficient. However, I find it prettier if HTTP requests never made it to the right server. It would also help scale your configuration if you end up with services not (yet) supporting HTTPS.
As for the arguments, I took your provided examples to the letter. If you wish to have some other arguments you do not want to touch and you want to redirect in a generic fashion, you may need to chain several map
(or use if
if you know what you are doing) to rewrite the $args
variable, ending up with a rewritten construction ready to be sent to the redirection URL.
answered Nov 17 '14 at 11:24
Bernard RossetBernard Rosset
1,115920
1,115920
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2fserverfault.com%2fquestions%2f643677%2fnginx-multiple-cross-domain-301-redirects-with-different-page-addresses%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
Possible duplicate of this
– wurtel
Nov 12 '14 at 10:04
Not a duplicate of that question. Also, updated the OP to be more specific.
– eclipsis
Nov 13 '14 at 3:07