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.
Questions tagged [rewrite]
2074 questions
87
votes
4 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,025
- 1
- 8
- 7
76
votes
10 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
- 883
- 1
- 8
- 8
75
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,479
- 3
- 12
- 23
73
votes
4 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,285
- 3
- 22
- 20
72
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
- 3,905
- 12
- 34
- 55
68
votes
2 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
51
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
41
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,292
- 3
- 23
- 38
38
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,143
- 1
- 12
- 19
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
- 978
- 7
- 20
- 32
27
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
- 674
- 1
- 5
- 10
25
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
- 399
- 1
- 4
- 11
24
votes
10 answers
How to inject HTML code into every delivered HTML page?
I've got an Apache web server that delivers static HTML pages. For some reason I can't change the files themselves, but I still want to inject some HTML into every page that is being served.
Is this possible with mod_proxy? If not, could anyone…
Node
- 1,644
- 1
- 13
- 15
23
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…
Peter Kirn
- 333
- 1
- 2
- 5
22
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…
CppLearner
- 767
- 3
- 10
- 24