Remove two parts of url permanantly - http

I have redesigned a website and changed the url formats too. Now i need to change the old url to new one.
Here is my old url:
/solumina-G8/api/v1.0/user-avatar/avatarImage/currentUser
The new url would be:
/api/user-avatar/avatarImage/currentUser
I was successful remove just one of them using rewrite rule
rewrite ^/solumina-G8(.*)$ $1 permanent;
But I can't find how to remove both Solumina-g8 and v1.0

Try this:
rewrite ^/solumina-G8/api/v1.0/(.*)$ /api/$1 permanent;

Related

nginx rewrite middle of url to another pattern

This nginx rule works great for me for a full specified file path
rewrite ^/sitemap.xml$ /sitemap.php last;
When I acces sitemap.xml it works as expected but in the background sitemap.php is requested. So far so goode.
Another problem arised and I need to rewrite the last part of existing urls
rewrite ^doctor-solution.html/ doctor-answer.html/ permanent;
What I want to achive is when an old url like
https://example.com/case12232-doctor-solution.html/ is accessed
it must be redirected to
https://example.com/case12232-doctor-answer.html/
But My rule doesn't seem to work. Any ideas?

Nginx rewrite rule: Add subfolder to URI if not there

Hello I'm trying to write a Nginx rewrite rule that adds a subdirectory to my URL if it's missing. For example, I need http://example.com to be re-written (and redirected) to http://example.com/legacy-app. Can't seem to find the proper example to do this.
You can use a rewrite directive, but an exact match location block is most efficient:
location = / {
return 301 /legacy-app;
}
See this document for more.
We ended up using this:
rewrite ^/$ /legacy-app/ last;

Nginx rewrite simple issue

I've migrated my site and now got a huge list of links that I need to redirect to their corresponding new urls. I'm not a developer or sys admin and can't really help myself with the Nginx manuals.
A short snippet of my list looks like this:
rewrite /?tn=productview&c=34223&pid=8965214 /url1 permanent;
rewrite /?tn=productview&c=54424&pid=6180497 /url2 permanent;
rewrite /?tn=productview&c=54426&pid=2563446 /url3 permanent;
rewrite /?tn=productview&c=54426&pid=6889674 /url4 permanent;
The problem is that Nginx will in that particular case redirect the first line correctly and all following lines to "url1".
How should I write this so that each of this links be redirected to their corresponding new url?

nginx redirect old URL to new URL

We just updated all our product url to new url. It only add some letter in the URL.
An example
old URL:
http://www.example.com/parent/children/product.html
new URL:
http://www.example.com/new-parent/children/product.html
(just added "new-" in "parent")
I try with this but not work.
location /parent {
rewrite ^/parent(.*) http://$server_name/new-parent$1 permanent;
}
So anyone can help me to correct this redirection?
Try to put rewrite ^/parent(.*) http://$server_name/new-parent$1 permanent; into server directive, not into /parent location.

Rewrite old image url with nginx

I have a single image that I renamed and need to redirect from the old image url to the new one my server uses nginx, I'm not having much success with the following rewrite:
rewrite ^/assets/avatar/avatar.png /assets/avatar/newavatar.png permanent;
Does someone know what is wrong?
If you want to use rewrite you need to use a full path to the new location
rewrite ^/assets/avatar/avatar.png http://example.com/assets/avatar/newavatar.png permanent;
A better way though is using a return
location /assets/avatar/avatar.png {
return 301 $scheme://example.com/assets/avatar/newavatar.png;
}
If you want to just rewrite, you need to change permanent to last or break

Resources