In the nginx.conf of website.com I put this:
rewrite ^test/(.+)$ http://www.websitenew.com/test/$1 permanent;
Then when I use curl -I www.website.com/test/en I got this in the redirection header:
Location: http://www.websitenew.com//test/en
I can see that website.com had successfully rewritten to websitenew.com and the URL scheme is also correct, but why there is one more / between websitenew.com and /test?
Thanks,
rewrite ^test/(.+)$ http://www.websitenew.com/test/$1 permanent;
This rule can't work actually, and your redirect is made by something else. There's no URI in nginx that not start with /, but your rule doesn't have / at the beginning.
Related
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;
}
Using nginx as a reverse proxy, I'd like to mimic the index directive with proxy_pass. Therefore I'd like nginx to query /index.html instead of /, /sub/index.html instead of /sub/.
What would be the best approach to do this ?
Not sure if it's relevant, but the proxied server does answer HTTP 200 on /, but I'd still like to rewrite it to /index.html.
As the / request leaks some information by listing the directory content, I'd also like to be sure that no one will be capable of accessing it (like doing something like /sub/..).
Thanksies
Just add :
rewrite (.*)/$ $1/index.html last;
rewrite (.*)/..$ $1/../index.html last;
Should works
Please help me with nginx:
url www.server.com/products/customer/books
should be www.server.com/customer/products/books
So i need to swap /products/ with /customer/
Yes, you can do this with a rewrite. Add the following to your server block:
rewrite ^/customer/products/(.*)$ /products/customer/$1 last;
Or, if you have multiple URLs (ie customer & business), you can do this:
rewrite ^/(customer|business)/products/(.*)$ /products/$1/$2 last;
I am using nginx to rewrite some urls. how would I take the wildcard part of the initial url and apply it to the destination url?
ex. ^/il-it/news /news where news is its the wildcard and its auto applied to the destination.
rewrite ^/il-it(/.*)?$ / permanent;
Try this -
rewrite ^/il-it/(.+)/?$ /$1 permanent;
We are currently getting web requests with www.domain.com//index.php which are resolving, but causing issues with google. How can we rewrite the request to catch these and redirect to www.domain.com/index.php
Thanks
By default ngingx merges double-slashes and urls like www.domain.com//index.php works well.
You can turn off merging and make rewrite rule with redirection:
merge_slashes off;
rewrite (.*)//(.*) $1/$2 permanent;