Got a rewrite rule for nginx;
if ($query_string ~ "page=search&shift=1&reset=1&search=([^&]+)(&searchButton=Zoek)?"){
set $search $1;
rewrite ^/?$ https://$host/zoeken/$search/? permanent;
}
When the search query hi/hi is performed, the output of the URL is:
website.com/zoeken/hi/hi, which returns a 404.
The expected outcome is website.com/zoeken/hi%52hi/
What is the correct rewrite rule to have the expected outcome?
Seems that in nginx we can't turn off or on URL encoding.
We got a choice to install another module, http://wiki.nginx.org/HttpSetMiscModule#set_escape_uri
But since we want to avoid installing modules, we set the rewrites rule in apache, rather than nginx.
Too bad.
Related
So I have a main path https://app.example.com and I want it to keep it that, way but on all https://app.expample.com/p/* paths I want it to be rewritten to a short version of the url like. How can I achieve this?
I tried
location = /p/(.*)$ {
rewrite ^ https://example.com/p/$request_uri permanent; and also return 301 https://example.com/p/$request_uri;
}
but this resulted in too many http redirects and an error
So we ran into an SEO issue with a WPML after changing from using URL parameters to specify the site language to using the path. The web server is running nginx.
Before:
example.com/?lang=fr
example.com/example-path/?lang=fr
After:
example.com/fr/
example.com/fr/example-path/
So what I'm trying to do is redirect any URL following the old URL format, including the root / to the new format. This process should strip all URI parameters in the URL and replace it with the corresponding path.
I reached out to the guys over at WPML and they don't know how to do it.
I've tried two different ways:
location = / {
if ($args ~ "^lang=(fr)") {
set $key1 $1;
rewrite ^.*$ /fr last;
}
}
As well as:
rewrite ^/.*\?lang\=fr$ /index.php? permanent;
But unfortunately from what I can tell, neither of these seem to do anything. I'm really familiar with regex but for some reason I'm having a hard time with these nginx rewrites.
I was surprised that there are very few examples in the nginx docs and on google about rewriting URL parameters. Any ideas on how this could be done?
Thanks!
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
the URL is:
http://xxxxxx/index.php?route=product/category&path=565
and why the heck the rules below dont work?!?!
THIS - dont work at all:
if ($request_uri ~* "^(.*)product/category&path=565"){
rewrite ^(.*)$ /index.php?route=product/category&path=174&filter=sale? last;
}
THIS - aint work too! =(
if ($args ~* "^(.*)product/category&path=565"){
rewrite ^(.*)$ /index.php?route=product/category&path=174&podbor=m:feniks? last;
}
Both of your rewrite rules work correctly (for me). The problem maybe that your application requires external redirection rather than internal redirection in order to see the change.
Consider using the redirect modifier rather than the last modifier. Of course, this will mean that the client will also see the rewritten URL.
See this document for more.
I'm new to nginx and I got a rewrite problem here:
I want to permanently redirect http://domain1.com/abc.php to http://domain2.com,
but I want to keep http://domain1.com/abc.php?param=value, I've tried put
rewrite ^/abc\.php$ http://domain2.com last;
which works for http://domain1.com/abc.php, unfortunately it rewrites everything that starts with the '/abc.php', I'm really confused why this is happening, any ideas?
Thanks in advance.
Nginx rewrites generally don't "see" the query string as part of the URI, which is why your existing rewrite isn't working - to Nginx it's always ^/abc\.php$ whether there's a query string or not.
Instead, I'd try this (adapted from the documentation):
if ($args !~ param=value) {
rewrite ^/abc\.php$ http://domain2.com permanent;
}
But be aware that if is evil.