Rewrite url with parameters in Nginx - nginx

i need rewrite this url in nginx, from:
http://domain.com/index.php?src=pictures/2014/11/23/1ZWi3tmM.jpg&w=330&h=186&a=c
to something like this
http://domain.com/thumb/300x186/ac/pictures/2014/11/23/1ZWi3tmM.jpg
i tried with this rule
rewrite /thumb/([0-9.]+)x([0-9.]+)/ac/([A-Za-z0-9.]+) index?src=$1&w=$2&h=$3&a=c;
but no luck. Any suggestion?
I've no experience with nginx, sad but true. Thank you

Related

How to rewrite /file/(name) to /q.html?id=(name) in NGINX

For example, rewriting /file/example to /q.html?id=example or /file/test to /q.html?id=test using NGINX.
How would that look like?
There are a number of ways of preforming an external redirect in Nginx, but the simplest solution would be:
rewrite ^/file/(.+)$ /q.html?id=$1 redirect;
See this document for details.

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 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;
# ^

nginx: Redirect special characters like "%23" in URL to "#"

My nginx site has a few bad links pointing to it like this:
/some-page%23some-part
/some-page">
This is causing 404's and Google Webmaster Tools is complaining too.
The URL /some-page#some-part does get processed properly and works.
How can I get nginx to redirect the %23 in a URL to #? What about the "> junk?
The links out there cannot be changed, so I'm looking to 301 redirect them myself.
Thanks!
Edit: thanks to Deadooshka for the help. My working solution, rewrite ^(.*)\#(.*)$ /$1#$2 redirect;, is discussed within his answer's comment thread.
not tested. I'm not sure which symbols get the pattern.
rewrite ^/([^\#]+)\#([^\#]+)$ /$1#$2 redirect;
rewrite '^/([^\&]+)\&quot\;\&gt\;$' /$1 redirect;

Timthumb.php Rewrite Seo Friendly URL (Nginx)

I started using nginx today.
These codes was working well rewrite on Apache.
RewriteRule ^thumb/(.*)x(.*)_(.*) styles/timthumb.php?src=http://image.mysite.org/uploads/$3&h=$2&w=$1&zc=1 [NC,L]
Url structure like this
http://www.mysite.org/styles/timthumb.php?src=http://image.mysite.org/uploads/fasulye.jpg&h=134&w=228&zc=1
To
http://www.mysite.org/thumb/228x134_fasulye.jpg
I want make friendly seo link of thimtumb with Nginx. Please help me. :(
Sorry my bad English.
You don't need to change much of the apache format
rewrite ^thumb/(.*)x(.*)_(.*) styles/timthumb.php?src=http://image.mysite.org/uploads/$3&h=$2&w=$1&zc=1 last;

Resources