Questions tagged [rewrite]

URL Rewriting maps an incoming URL to a modified URL, so that the request is processes as if the original request was made to the modified URL. This is often used to provide more search engine friendly URLs.

2146 questions
97
votes
5 answers

What is the difference between Nginx variables $host, $http_host, and $server_name?

What is the difference between the three Nginx variables $host, $http_host, and $server_name? I have a rewrite rule where I'm not sure which one I should be using: location = /vb/showthread.php { #…
Jeff Widman
  • 2,675
91
votes
5 answers

Nginx Redirect via Proxy, Rewrite and Preserve URL

In Nginx we have been trying to redirect a URL as follows: http://example.com/some/path -> http://192.168.1.24 where the user still sees the original URL in their browser. Once the user is redirected, say they click on the link to…
robjohncox
  • 1,065
86
votes
5 answers

Nginx redirect one path to another

I'm sure this has been asked before, but I can't find a solution that works. A website has switched CMS services, but has the same domain, how do I set up an nginx rewrite for a single page? E.g. Old…
SteveEdson
  • 1,609
85
votes
1 answer

Nginx - Meaning of the ~ (tilde) in the location block of the nginx.conf?

What is the meaning of the tilde after the location block in the nginx configuration? for example location ~ ^/download/(.*)$ { alias /home/website/files/$1; } What is the difference between with and without the "~" ?
mahen3d
  • 4,682
84
votes
4 answers

nginx url rewriting: difference between break and last

I don't understand the difference between break and last (flags of rewrite). The documentation is rather abstruse. I've tried to switch between the two in some of my configs, but I couldn't spot any difference in behavior. Can someone please explain…
user39883
81
votes
11 answers

Remove "www" and redirect to "https" with nginx

I want to create a rule in nginx that does two things: Removes the "www." from the request URI Redirects to "https" if the request URI is "http" There are plenty of examples of how to do each of those things individually, but I can't figure out a…
Devin
  • 933
57
votes
4 answers

how to restrict access to directory and subdirs

I need to restrict access to any files or subdirs in direstory "testdir". My conf: ... location ~* ^.+\.(jpg|txt)$ { root /var/www/site; } location /testdir { deny all; return 404; } ... In my…
tst
49
votes
2 answers

How to quick and easy remove part of an URL in Nginx with HttpRewriteModule?

I know about the HttpRewriteModule, but I don't really know how to handle regex and I would need to redirect all URLs within a certain directory to another, specifically: From: example.com/component/tag/whatever To: example.com/tag/whatever Could…
javipas
  • 1,372
39
votes
3 answers

How to rewrite the domain part of Set-Cookie in a nginx reverse proxy?

I have a simple nginx reverse proxy: server { server_name external.domain.com; location / { proxy_pass http://backend.int/; } } The problem is that Set-Cookie response headers contain ;Domain=backend.int, because the backend does not know…
Tobia
  • 1,273
35
votes
2 answers

Disabling URL decoding in nginx proxy

When I browse to this URL: http://localhost:8080/foo/%5B-%5D server (nc -l 8080) receives it as-is: GET /foo/%5B-%5D HTTP/1.1 However when I proxy this application via nginx (1.1.19): location /foo { proxy_pass …
Tomasz Nurkiewicz
  • 834
  • 1
  • 7
  • 10
31
votes
3 answers

HAProxy reqrep remove URI on backend request

real quick question regarding HAProxy reqrep. I am trying to rewrite/replace the request that gets sent to the backend. I have the following example domain and URIs, both sharing the same domain name, but different backend web server…
Jim
  • 988
27
votes
1 answer

How can I export URL rewrite rules?

Is it possible to export URL rewrite rules for IIS7? I am setting up a duplicate of a website for internal use (testing) and want to duplicate all of the URL Rewrite rules without having to manually enter them. There is an import option, but no…
Matt
  • 419
25
votes
4 answers

nginx + PHP-FPM = "permission denied" error 13 in nginx log; configuration mistake?

I've got nginx 0.7x + PHP-FPM running under PHP 5.2.10 on one RHEL5 server, but trying to duplicate that setup under the bundled-in PHP-FPM in PHP 5.3.3 on a second server, I'm having some trouble with permission errors every time there's a GET. FPM…
24
votes
4 answers

Nginx https rewrite turns POST to GET

My proxy server runs on ip A and this is how people access my web service. The nginx configuration will redirect to a virtual machine on ip B. For the proxy server on IP A, I have this in my sites-available server { listen 443; ssl…
23
votes
2 answers

Redirect only home page

I need to redirect only http://shop.test.com to http://www.test.com/fedex-orders/ Just homepage. Nothing else. ie http://shop.test.com/?page=blog should NOT redirect.
Harikrishnan
  • 1,419
1
2 3
99 100