Home Nginx 301 Redirect not working correctly
Reply: 1

Nginx 301 Redirect not working correctly

Lee
1#
Lee Published in 2017-12-05 09:55:09Z

I'm trying to redirect all traffic from one subfolder to another. For example:

www.website.com/ve/12345.html

to

www.website.com/es/12345.html

My nginx command:

rewrite ^/(ve)/(.*)$ /es/$1 permanent;

Does the following:

www.website.com/ve/12345.html

to

www.website.com/es/ve

How can I replace ve with es and keep the rest of the URL intact?

Jeremy Jones
2#
Jeremy Jones Reply to 2017-12-05 10:25:36Z

The problem is that you've used $1 in your replacement, but $1 is just the characters 've', not the extra stuff at the end, which is in $2 in your version.

Best would be to remove the extra capture group so that you're not capturing things you're not using. This rule will do the redirect ok:

rewrite ^/ve/(.+)$ /es/$1 permanent;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305119 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO