remove /profile/ from a link - nginx

On my site my users click on a profile and the link shows up as www.website.com/profile/username and I would like it to only be www.website.com/username - any suggestions on how I can do this
Note: my webserver is nginx so using rewrite rules is ok, but I would want to know how to write them in the config file

Use the following rewrite rule:
rewrite ^/profile/(.*)$ /$1 permanent;

Related

nginx how to redirect all pagination

I need help with my nginx configuration.
The goal is to have all requests to my site like site/page1 site/smth/page1 be redirected to just site/ and site/smth/ basically for all requests ending like page[number]
I tried some examples that I found like rewrite ^/page/(.*)$ /$1; still wasn't able to get the redirection. Maybe I misplaced it, not quite sure where I should put the sting. Tried location and server blocks.
The nginx documentation examples for redirecting were a bit too hard to understand for me, so a little explanation would be great.
If you need a 301 HTTP redirection, try this rewrite rule (before the first location block):
rewrite ^(.*/)page\d+$ $1 permanent;
You can try something like this (not tested)
location ~ ^/(.+)/page[0-9]+$ {
rewrite ^/(.+)/page[0-9]+$ /$1 last;
}

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 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 Rewrite Not rewriting the url

I have tried this for hours and can't seem to get it. I copied other examples and still can't get rewrite to work.
I need my url on nginx to look like http://myurl.com/main/login, http://myurl.com/somethigelse/home, est. Any Help Appreciated. I'm new to nginx, seems a lot faster.
My nginx rewrite looks like this:
rewrite ^/([^/]+)/([^/]+)$ /index.php?db=$1&action=$2 last;
rewrite ^/([^/]+)/([^/]+)/$ /index.php?db=$1&action=$2 last;
It works for me. Do you tell nginx to reload the configuration (do a sudo service nginx reload)? Otherwise, nginx will still be using the old config.
Note, that you can use one line by making the final slash optional using a question mark:
rewrite ^/([^/]+)/([^/]+)/?$ /index.php?db=$1&action=$2 last;
# ^

vBulletin archive rewrite rules on Nginx

I got a problem for vBulletin archive running on Nginx 0.8.54. The Nginx gives me 404 error when I try visiting the following URLs
http://mydomain.com/forums/archive/index.php/t-19.html
http://mydomain.com/forums/archive/index.php/f-19.html
All other things of vBulletin works fine. Can anybody may share its rewrite rule to fix my problem ?Thanks.
Try something like:
location /archive {
rewrite ^/archive/index.php/t-([0-9]+)\.html /archive/index.php?t-$1.html last;
rewrite ^/archive/index.php/f-([0-9]+)\.html /archive/index.php?f-$1.html last;
}

Resources