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)

Filter by
Sorted by
Tagged with
0 votes
1 answer
154 views

HOW Check Url Parametr and Redirect with Nginx rewrite

I want to check if a parameter is present in a url in nginx and then rewrite. How can i do that? For e.g if url is http://website.com/search/node/item123/loc=33 then redirect to http://website.com/...
Bijan Zand's user avatar
1 vote
1 answer
46 views

Nginx: rewriting while checking args format with a regex

I have an API endpoint like /my/api/PARAM1/abcd?arg1=val1&arg2=val2, and use a redirect to proxy to a fastcgi server elsewhere (using upstream). Basically I have the current configuration : ...
fred59xc06's user avatar
0 votes
0 answers
257 views

Nginx equivalent for apache mod_rewrite rule

My script is hosted on centos 7 apache server, with below htaccess: <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> ...
ktiwari's user avatar
1 vote
0 answers
134 views

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 ...
Olivier THIERRY's user avatar
1 vote
1 answer
265 views

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-...
zigojacko's user avatar
  • 1,453
0 votes
0 answers
187 views

nginx regex rewrite not working for php script

I am trying to block PHP script execution in few folders for a WordPress installation but Nginx is giving me hard time. location = /wp/wp-includes/category.php { deny all; } I am able to block ...
Maximus's user avatar
  • 355
1 vote
0 answers
3k views

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 ...
Adesso's user avatar
  • 203
2 votes
1 answer
408 views

Exclude google doc embed iframe from nginx rewrite rule?

I hope that someone can help me here as I have very limited knowledge about server related stuff. I have a WordPress site where I want to limit the /wp-content/uploads/ directory access to logged in ...
bakar's user avatar
  • 21
1 vote
0 answers
67 views

WordPress Date Archives not working in Nginx

WordPress installed in a subdirectory: domain.com/folder WordPress Permalink Settings: domain.com/folder/%postname% Referencing the WordPress Nginx support article, I added the following to my nginx ...
webdev's user avatar
  • 11
2 votes
1 answer
351 views

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 ...
NoobAvi's user avatar
  • 23
1 vote
1 answer
407 views

Rewrite uri to remove www in nginx

I have an unknown number of domains that match a pattern like www.abc123.example.com. Where the number after "abc" is unknown. I thought perhaps I could use a rewrite rule with the regex ~*(...
LK86's user avatar
  • 55
1 vote
2 answers
827 views

NGINX 1.13.8 Rewrite url not works

I have following location with rewrite: location ~ ^/payment/gateway/v2/order/complete/(.*)$ { proxy_pass http://api.test.com:8080/payment/gateway/v2/order/complete?order_id=$1; } then I tried ...
SBotirov's user avatar
0 votes
2 answers
1k views

Rewrite image request to sub-directory structure in Nginx

Given a location like this: location ~ ^/user-content/img/) { root /srv/foo/bar/uploads/; autoindex off; access_log off; expires 30d; } Is it possible using nginx to have a request for /user-...
Oliver Weichhold's user avatar
0 votes
0 answers
36 views

Need help on nginx url rewriting

I'm having trouble rewriting this URL below: https://domain-name.com/2020/10/title_of_article.html?id=1 into: https://domain-name.com/0/1 the year is unnecessary so it is removed/truncated/ignored ...
ikevin8me's user avatar
  • 137
0 votes
2 answers
3k views

Nginx rewrite/return phase order

I know there are Nginx phases. Why does the following snippet deliver the "200 Host: example.com" instead of forwarding to Google? What would be a generally valid workaround to evaluate Lua ...
uav's user avatar
  • 554
1 vote
1 answer
588 views

Converting htaccess to Nginx ReWrite (autoconverting not working)

Hi there anyone happens to know Nginx rewrite rules? I'm trying to convert this Apache .htaccess to Nginx Rewrite, I already tried with online converters the homepage and dashboard once logged in work ...
Elin Digente's user avatar
0 votes
1 answer
2k views

Nginx redirect to main domain from subdomain without changing URL in address bar

I have a domain and wildcard subdomains. main domain: example.com subdomains: s1.example.com, s2.example.com etc. Now the requirements is s1.example.com will be redirect to example.com/organization/...
Rakibul Hasan's user avatar
0 votes
0 answers
456 views

How to count the number PDF downloads using PHP on an NGINX server - conversion of Apache Rewrite Rule

I found excellent rewrite rules and a PHP script that works with Apache to count the number of downloads for certain file types. I need this converted to be NGINX friendly. The Apache rewrite rules ...
Eugene van der Merwe's user avatar
1 vote
2 answers
3k views

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'...
HelenSaepp's user avatar
1 vote
2 answers
1k views

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: ...
Sandro Benevides's user avatar
1 vote
0 answers
2k views

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'; ...
reschandreas's user avatar
1 vote
1 answer
1k views

nginx rewrite based on part of URL

I'm trying to set up nginx rewrites; I have it successfully set up to remove the extension: https://example.com/accounts?id=user-123 points to https://example.com/accounts.php?id=user-123 using just ...
ieatpizza's user avatar
  • 113
1 vote
0 answers
964 views

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-...
MacUsers's user avatar
  • 479
1 vote
2 answers
1k views

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 ...
BarsMonster's user avatar
0 votes
1 answer
911 views

How to redirect all requests except when there's an exact string match

Requirement- I want to redirect all requests that end with /abcd to /products/abcd This should match all urls such as these- /collection/abcd /collections/all/abcd /hello/world/abcd This is what i'...
Mridul Aggarwal's user avatar
0 votes
1 answer
112 views

Nginx Node Proxypass Result to Variable

I want create some rewrite with nginx (5 million links), I read nginx have the option to save it in a map file but need ages to reload + ram usage when I do it this way. My Idea was now User -> ...
StefanBD's user avatar
  • 101
0 votes
1 answer
98 views

port RewriteRule from apache to nginx

we have a large php application running on apache now which I would like to migrate to nginx. I’ve got everything to work correctly except for a RewriteRule in a .htaccess file. The web app allows ...
dingenling's user avatar
0 votes
1 answer
343 views

PHP script path inconsistencies on nginx with multiple server root paths

I'm struggling a bit with some nginx configuration. Essentially I have one filesystem folder (/remote) that hosts web content at /, but on top of this I want virtual paths /w and /wiki that will host ...
Malvineous's user avatar
  • 1,105
1 vote
0 answers
1k views

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 ^(.*)$ ...
Potatoswatter's user avatar
0 votes
2 answers
696 views

nginx rewrite : [emerg] unknown "0" variable

1.) Apache Rule: RewriteRule ^(.*)/(.*).htm$ /inner.php?Categories=$0&Title=$1 [L,QSA] 2.) After converting to nginx: rewrite ^/(.*)/(.*).htm$ /inner.php?Categories=$0&Title=$1 break; ...
user3136863's user avatar
2 votes
2 answers
924 views

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; ...
Nick Rolando's user avatar
2 votes
2 answers
24k views

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 to https://example....
Vince's user avatar
  • 51
0 votes
1 answer
113 views

converting htaccess url rewriting rules into nginx

How can i convert my htaccess rules here RewriteRule ^/?([^/]+)/([^/]+)/?$ page-1.php?a=$1&b=$2 [L,QSA] RewriteRule ^/?([^/]+)/([^/]+)/([^/]+)/?$ page-2.php?a=$1&b=$2&c=$3 [L,QSA] into ...
Axon's user avatar
  • 3
0 votes
1 answer
39 views

How do I rewrite these URL's?

I'm working on an ancient (1989!) website which, back in the days, just showed a file directory in some cases. I want to use rewrites to show people a proper file instead. Case: I have 3 folders, 01, ...
Evert's user avatar
  • 162
1 vote
1 answer
8k views

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 ...
Andrew Newby's user avatar
  • 1,124
1 vote
1 answer
53 views

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 ...
Raymond's user avatar
  • 11
0 votes
1 answer
590 views

Double rewrite request

I have nginx and I trying create rule in the double condition (if) and double rewrite. The schema is: URL (/direct/file.11223344_aabbcc.js) -> if no file -> [Yes] rewrite to /direct/file_aabbcc.js -> ...
Piknik's user avatar
  • 53
1 vote
1 answer
2k views

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 ...
JohnsonGoey's user avatar