Nginx simple redirect of products from old to new category
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm making redirects of products from old to new category.
I've managed to make it work with following rule:
rewrite ^/old-category/(.*) /new-category/$1;
But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:
rewrite ^/old-category/(.*)$ /new-category/$1;
Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.
Thank you for your answers in advance.
nginx redirect rewrite
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
I'm making redirects of products from old to new category.
I've managed to make it work with following rule:
rewrite ^/old-category/(.*) /new-category/$1;
But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:
rewrite ^/old-category/(.*)$ /new-category/$1;
Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.
Thank you for your answers in advance.
nginx redirect rewrite
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm making redirects of products from old to new category.
I've managed to make it work with following rule:
rewrite ^/old-category/(.*) /new-category/$1;
But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:
rewrite ^/old-category/(.*)$ /new-category/$1;
Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.
Thank you for your answers in advance.
nginx redirect rewrite
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm making redirects of products from old to new category.
I've managed to make it work with following rule:
rewrite ^/old-category/(.*) /new-category/$1;
But I want to know when should I use "end line" sign $ and what's the difference with it or without it in my case. For example:
rewrite ^/old-category/(.*)$ /new-category/$1;
Also I want to redirect users if they simply write old category name (without products), should I create a new rule just for category redirect or I can edit the current rule above to work in both cases.
Thank you for your answers in advance.
nginx redirect rewrite
nginx redirect rewrite
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 hours ago
Analogtime
111
111
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Analogtime is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Hello and welcome to Server Fault.
Answering your questions in order...
This
rewrite ^/old-category/(.*) /new-category/$1;
and this
rewrite ^/old-category/(.*)$ /new-category/$1;
as written are equivalent. The .*
rule matches 0 or more of "everything".
The $
terminator is useful when you want to match strings that end in a specific way, for example
rewrite ^/old-category/(.*).php$ /new-category/$1;
to rewrite only PHP files.
As for your second question, if I understood correctly, you want to redirect this
http://example.com/old-category/
to this
http://example.com/new-category/
If that's so, it's already done by the rewrite
rule, as .*
matches ZERO or more characters.
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Hello and welcome to Server Fault.
Answering your questions in order...
This
rewrite ^/old-category/(.*) /new-category/$1;
and this
rewrite ^/old-category/(.*)$ /new-category/$1;
as written are equivalent. The .*
rule matches 0 or more of "everything".
The $
terminator is useful when you want to match strings that end in a specific way, for example
rewrite ^/old-category/(.*).php$ /new-category/$1;
to rewrite only PHP files.
As for your second question, if I understood correctly, you want to redirect this
http://example.com/old-category/
to this
http://example.com/new-category/
If that's so, it's already done by the rewrite
rule, as .*
matches ZERO or more characters.
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
add a comment |Â
up vote
2
down vote
Hello and welcome to Server Fault.
Answering your questions in order...
This
rewrite ^/old-category/(.*) /new-category/$1;
and this
rewrite ^/old-category/(.*)$ /new-category/$1;
as written are equivalent. The .*
rule matches 0 or more of "everything".
The $
terminator is useful when you want to match strings that end in a specific way, for example
rewrite ^/old-category/(.*).php$ /new-category/$1;
to rewrite only PHP files.
As for your second question, if I understood correctly, you want to redirect this
http://example.com/old-category/
to this
http://example.com/new-category/
If that's so, it's already done by the rewrite
rule, as .*
matches ZERO or more characters.
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Hello and welcome to Server Fault.
Answering your questions in order...
This
rewrite ^/old-category/(.*) /new-category/$1;
and this
rewrite ^/old-category/(.*)$ /new-category/$1;
as written are equivalent. The .*
rule matches 0 or more of "everything".
The $
terminator is useful when you want to match strings that end in a specific way, for example
rewrite ^/old-category/(.*).php$ /new-category/$1;
to rewrite only PHP files.
As for your second question, if I understood correctly, you want to redirect this
http://example.com/old-category/
to this
http://example.com/new-category/
If that's so, it's already done by the rewrite
rule, as .*
matches ZERO or more characters.
Hello and welcome to Server Fault.
Answering your questions in order...
This
rewrite ^/old-category/(.*) /new-category/$1;
and this
rewrite ^/old-category/(.*)$ /new-category/$1;
as written are equivalent. The .*
rule matches 0 or more of "everything".
The $
terminator is useful when you want to match strings that end in a specific way, for example
rewrite ^/old-category/(.*).php$ /new-category/$1;
to rewrite only PHP files.
As for your second question, if I understood correctly, you want to redirect this
http://example.com/old-category/
to this
http://example.com/new-category/
If that's so, it's already done by the rewrite
rule, as .*
matches ZERO or more characters.
answered 52 mins ago
Mr Shunz
2,06111819
2,06111819
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
add a comment |Â
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
Good question, good answer. So many people set the $ by default (or leave it out by default) without thinking about what it actually means. Every time I see (.*)$ I cringe. I didn't try it but it might actually be that leaving out the $ in this case could have a slightly better performance as it's another rule regex has to check for. Would be interesting to get an answer to that question :D
– Broco
42 mins ago
add a comment |Â
Analogtime is a new contributor. Be nice, and check out our Code of Conduct.
Analogtime is a new contributor. Be nice, and check out our Code of Conduct.
Analogtime is a new contributor. Be nice, and check out our Code of Conduct.
Analogtime is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f934465%2fnginx-simple-redirect-of-products-from-old-to-new-category%23new-answer', 'question_page');
);
Post as a guest
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
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
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