Questions tagged [ngx-http-rewrite-module]

nginx rewrite module is a default module that implements if-statements, rewrite directives and allows URL manipulation in nginx with the help of PCRE regular expressions (it's what mod_rewrite is to Apache)

The ngx_http_rewrite_module module of is used to change request URI using PCRE , return redirects, and conditionally select configurations.

It is similar in its concept to of Apache.

http://nginx.org/docs/http/ngx_http_rewrite_module.html

http://ngx.su/src/http/modules/ngx_http_rewrite_module.c

35 questions
2
votes
2 answers

Finish processing rewrite directives in location and return 301

I have the following in my nginx.conf: location ~* /collections.*?products/([^/]+)/?$ { rewrite ^/collections.*?products/([^/]+)/?$ /$1.html; rewrite ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3; rewrite ^([^_]*)_(.*)$ $1-$2 permanent; } To…
2
votes
1 answer

Apache .htaccess to NGINX RewriteRules Port

So, I am actually trying to port the RewriteRules from Apache to NGINX but it seems I am not able to completely port out. Actually, on my server I do have a running site on https://example.com domain and /var/www/html/ path on the server. What I am…
NoobAvi
  • 23
  • 4
1
vote
2 answers

How to Nginx rewrite to get clean url of page numbers

Recently we have moved to Nginx from Apache, Under apache it used to be very easy just put some stuff on .htaccess and done. RewriteEngine on RewriteBase / # only rewrite if the requested file doesn't exist RewriteCond %{REQUEST_FILENAME} !-s #…
1
vote
2 answers

How to convert this very simple .htaccess to Nginx?

I'm using this .htaccess that pass everything after URL to $param, so example.com/news/id goes to PHP as $_GET['param']='news/id'. But Nginx is always throwing me to 404 page. My .htaccess: RewriteEngine On RewriteCond %{SCRIPT_FILENAME}…
1
vote
0 answers

How to filter urls with sub_filter with nginx

I recently was given the task of setting up a proxy and everything works great now, except that I can't seem to filter basic urls with sub_filter. This code works flawlessly sub_filter 'anna' 'bob'; But the second I add a slash to the search…
1
vote
0 answers

Nginx: how to rewrite HTTP_HOST keeping the original URL unchanged

A bit of background: When abc.mywebsite.com (or xyz.mywebsite.com and so on) is requested, it received by haproxy, which replaces the Host header with main.company.net and also adds the X-Custom-Header as abc (or xzy). Then these two headers are…
MacUsers
  • 449
  • 2
  • 7
  • 13
1
vote
2 answers

Nginx caching reverse proxy with URL rewrite

I am serving large static files from a backend storage server with slow spinning disks. This server is hidden behind fast nginx reverse proxy with local cache on SSD. It works great and fast. Now I want to change storage backend, and as a result I…
BarsMonster
  • 644
  • 3
  • 11
  • 24
1
vote
0 answers

nginx rewrite error, invalid number of arguments

I'm running nginx 1.13.6. The configuration has this directive to serve a virtual host service.company.com/ using service.company.com/svc/: if ($server_name = service.company.com) { rewrite ^(.*)$ /svc/$1 last; } The server starts successfully,…
1
vote
2 answers

nginx reverse proxy with query parameter modification

I have an application that is not SSL aware behind nginx, thus I need to do the following http://example.com/f1/f2/page?next_page=http%3A//example.com/f3/new_page has to change…
Vince
  • 31
  • 1
  • 1
  • 6
1
vote
1 answer

rewrite or internal redirection cycle while internally redirecting to, in nginx

I'm trying to get a rewrite rule to work for nginx and Wordpress. After a reboot of nginx, I try the site and get an IS 500 error page. The log file says: *1 rewrite or internal redirection cycle while internally redirecting to "/index.php" I'm…
Andrew Newby
  • 1,041
  • 1
  • 22
  • 48
1
vote
1 answer

Ngnix static site with one PHP alias/rewrite

I have a static site Angular site and I want to have the path /deploy run a php the php script /var/www/app/deploy/deploy.php. I have tried a rewrite rule and having no luck. What is the proper way to do this? php.conf index index.php index.html…
Raymond
  • 11
  • 1
1
vote
1 answer

add a URL suffix path (for mobile AMP) without causing a redirect loop in nginx

i am using nginx web server for my wordpress website. i am going to make it to become amp version for mobile serve. i wanna add /amp/ to my url. i also using pretty permalink for my current url,so may i know how can i rewrite my url in mobile…
1
vote
0 answers

Is it possible to have a regex in the replacement string of a rewrite rule in nginx

I need a quite special rewrite rule but I can’t find the way to do it. I need to map a uri to a regex to a replacement string built with a regex. For example I have a /pdv/plan-AGE44-ABC.pdf uri that could be mapped to the following ones…
1
vote
1 answer

Stop Nginx rewrites breaking all pages following location block

I'm having to rewrite URLs in nginx.conf that contain particular query parameters; As an example:- location /brands/exampleA { if ($arg_cat = "9") { return 301 /page/brand-filter; } if ($arg_cat = "38") { return 301…
zigojacko
  • 1,433
  • 2
  • 12
  • 25
1
vote
0 answers

Using URL's with special characters in nginx maps

When using nginx and maps it is possible to rewrite mutiple URL's with a map file. What is problematic is when the URL contains special characters. I have been breaking my head trying to get this right, and hope this Question / Solution might save…
Adesso
  • 203
  • 1
  • 2
  • 9
1
2 3