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.

Filter by
Sorted by
Tagged with
89 votes
4 answers
333k views

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 ...
robjohncox's user avatar
  • 1,045
89 votes
5 answers
105k views

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's user avatar
  • 2,515
82 votes
1 answer
65k views

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 ...
mahen3d's user avatar
  • 4,382
80 votes
5 answers
350k views

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. ...
SteveEdson's user avatar
  • 1,539
80 votes
2 answers
89k views

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 ...
user avatar
80 votes
11 answers
68k views

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 ...
Devin's user avatar
  • 923
53 votes
4 answers
144k views

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; ...
user avatar
46 votes
2 answers
113k views

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/...
javipas's user avatar
  • 1,342
39 votes
3 answers
117k views

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 ;...
Tobia's user avatar
  • 1,193
33 votes
2 answers
54k views

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 ...
Tomasz Nurkiewicz's user avatar
31 votes
3 answers
54k views

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 ...
Jim's user avatar
  • 988
26 votes
1 answer
36k views

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 ...
Matt's user avatar
  • 409
24 votes
4 answers
67k views

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 ...
Peter Kirn's user avatar
24 votes
10 answers
50k views

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 ...
Node's user avatar
  • 1,644
23 votes
2 answers
22k views

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's user avatar
  • 1,179
23 votes
4 answers
41k views

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-...
CppLearner's user avatar
21 votes
2 answers
78k views

nginx rewrite for an url with parameters

I have an URL of this type: http://www.example.com/?param1=val1&param2=&param3=val3&param4=val4&param5=val5 And I want to redirect it to this one: http://www.example.com/newparam/...
David Morales's user avatar
20 votes
3 answers
26k views

nginx case insensitive rewrite

I am trying to make my nginx redirects as clean as possible. I understand ~* is for case insensitive but I can only get it to work in example 2. Example 1 rewrite ^/foobar http://www.youtube.com/...
milleruni's user avatar
  • 303
20 votes
1 answer
21k views

maintaining redirects in nginx from an external source

I am in the situation to give our marketing department the opportunity to maintain their redirects by their own. Until now, they passed the information to the IT department and we maintained it for ...
Sascha's user avatar
  • 538
18 votes
4 answers
138k views

How to redirect requests to a different domain/url with nginx

I'm trying to redirect all users coming to a URL "http://example.com/something" to a URL like "http://answares.com/examples_com/something". I'm trying with code like this: server { listen 1.2.3.4:...
user93656's user avatar
  • 283
17 votes
5 answers
2k views

How can I enforce that my urls always start with www?

I want to ensure that users come to www.mydomain.com even if they arrive through the alias mydomain.com. This is so that I have control over cookies on subdomains, and so that Google sees one single ...
Magnar's user avatar
  • 1,047
17 votes
3 answers
27k views

Is it possible to replace content on every page passed through a proxy similar to how mod_rewrite is used for URLs?

Is it possible to replace content on every page passed through a proxy similar to how mod_rewrite is used for URLs? The documentation on substitute is not clear. I have some pages I am reverse ...
ZZ9's user avatar
  • 918
17 votes
2 answers
18k views

Prevent URL Rewrite rules from being inherited by subdirectories in IIS7

I have a URL Rewrite setup for clean URLs in a CMS and my web.config looks like this: <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <...
Rich Jenks's user avatar
17 votes
2 answers
19k views

"Hide" .html file extensions using nginx rewrites

I'm serving up a static site via nginx, and my goal is to replace URL's that look like: http://foo.com/bar.html with http://foo.com/bar The key being no trailing slash. I am currently doing ...
Doug Stephen's user avatar
17 votes
2 answers
20k views

How to use IIS URL Rewrite with gzip compression

I've been trying to create outbound rules in IIS 7.5 on Windows 2008 R2 on a site that has static HTML pages and compression enabled. If I have any form of compression enabled (static or dynamic) I ...
mpipe3's user avatar
  • 281
15 votes
3 answers
70k views

Nginx rewrite URL only if file exists

I need to write a rewrite rule for Nginx so that if a user tries to go to an old image url: /images/path/to/image.png and the file doesnt exist, try to redirect to: /website_images/path/to/image....
Jose Fernandez's user avatar
14 votes
2 answers
36k views

Nginx Rewrite Convert Querystring to Path

I whould like this simple rewrite rule: /somefolder/mypage.aspx?myid=4343&tab=overview to be redirected to: /folder/4343/overview/ I looked for some solutions and none actually worked.. I ...
YardenST's user avatar
  • 265
14 votes
2 answers
48k views

Nginx multiple roots

I'd like to divert off requests to a particular sub-directory, to another root location. How? My existing block is: server { listen 80; server_name www.domain.com; location / { ...
Michael restore Monica Cellio's user avatar
13 votes
1 answer
14k views

My nginx rewrite is downloading the php file

I have the following rewrite rule I'm trying: location / { index index.php index.html; rewrite ^/test$ /test.php break; } And I ...
willdanceforfun's user avatar
13 votes
3 answers
38k views

IIS URL Rewrite HTTP to HTTPS with Port

My website has two bindings: 1000 and 1443 (port 80/443 are in use by another website on the same IIS instance). Port 1000 is HTTP, port 1443 is HTTPS. What I want to do is redirect any incoming ...
Andy Arismendi's user avatar
13 votes
4 answers
43k views

Different nginx rules based on referrer

I'm using WordPress with WP Super Cache. I want visitors who come from Google (That inlcudes all country specific referrers like google.co.in, google.co.uk and etc.) to see uncached contents. There ...
user avatar
12 votes
1 answer
58k views

What is the difference between HTTP_HOST and HTTPS_HOST in apache .htaccess files?

I'm editing an .htaccess file.. In RewriteCondition for RewriteRules, HTTPS_HOST seems to only match urls that are accessed via https:// protocol (ssl). I saw in docs somewhere that it's a T/F ...
SherylHohman's user avatar
12 votes
4 answers
11k views

Configure IIS 7 Reverse Proxy to connect to TeamCity Tomcat

We have an IIS 7 webserver configured and would like to create a reverse proxy for a TeamCity installation using Tomcat on the same machine. The IIS server site is https://somesite and I would like ...
Cynicszm's user avatar
  • 121
12 votes
4 answers
29k views

Temporarily redirect *all* HTTP/HTTPS requests in IIS to a "server maintenance" page

We've got an IIS server that hosts hundreds of separate web apps, and the physical database server that hosts these apps is going to be taken offline for maintenance for a brief period (we expect it ...
Josh's user avatar
  • 287
11 votes
3 answers
62k views

Add samesite to cookies using Nginx as reverse proxy

With Nginx as reverse proxy, how do you add samesite=strict or samesite=lax to cookies?
Dr.Haribo's user avatar
  • 213
11 votes
1 answer
19k views

How to extract Only the file name from the request uri

I am trying to rewrite the request uri depending on the extension of the file, then extract only the file name from the uri and store it in another folder. The problem here is no predefined variable ...
Johnta's user avatar
  • 113
11 votes
2 answers
9k views

IIS Rewrite, rewrite maps and query strings

Please help me understand rewrite maps, I have this setup: <rewriteMap name="MyMap"> <add key="/pages" value="/website/pages/index.aspx" /> <add key="/pages/page-1" value="/...
Martin at Mennt's user avatar
11 votes
2 answers
33k views

Add trailing slash when it's missing in nginx

I'm running Magento on Nginx using this config: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento. Now I want to 301 all URLs without trailing slash ...
user avatar
11 votes
1 answer
19k views

nginx: rewrite all except one location

Right now my nginx is rewriting several domains to one main domain which we are using. Here's one rule from my config: server { listen X.X.X.X:80; server_name .exampleblog.org; rewrite ^(.*) ...
lorem monkey's user avatar
10 votes
3 answers
28k views

Apache: Where to examine the redirection logs?

I have complicated RewriteCond and RewriteRule in one machine. And according to these rules, some of the requests will be redirected to another machine. So is there any Apache log that shows clearly ...
Graviton's user avatar
  • 2,905
10 votes
3 answers
8k views

mod_rewrite does not forward GET parameters

I'm having trouble setting up Apache with mod_rewrite on my development machine. Mod_rewrite is active, and works well for some rules. Some rules do not work as intended, like this one: RewriteRule ^...
Vegard Larsen's user avatar
10 votes
3 answers
30k views

How do I make RewriteCond %{HTTP_COOKIE} match a cookie value exactly? [duplicate]

How do I make my rule match an exact value of a cookie? I've tried: RewriteCond %{HTTP_COOKIE} ^its=me$ [NC] RewriteCond %{HTTP_COOKIE} its=^me$ [NC] RewriteCond %{HTTP_COOKIE} its="me" [NC] ...
Nick's user avatar
  • 4,521
10 votes
1 answer
25k views

nginx - specify different index file name for subdirectory

I want the directory index file in the root of my site to be index.html but within a subdirectory /foo I want it to be bar.html i.e. /index.html /foo/bar.html Also I want requests to /foo or /foo/ ...
Ade's user avatar
  • 709
10 votes
2 answers
31k views

nginx $uri is url decoded

I am using nginx as reverse proxy and I have 2 rules like: location ~ ^/indirect { rewrite ^/indirect(.*) /foobar$1; } location ~ ^/foobar { set $url http://example.com/something/index.php?var1=...
Carlos Campderrós's user avatar
9 votes
2 answers
45k views

nginx redirect to www.domain

I want to redirect the site ALWAYS to www.site.com. However, I am not sure as to how to get the WWW to always show up in front should say someone type in the domain without the www. EDIT: server { ...
Jake Thomas's user avatar
9 votes
1 answer
14k views

Apache 2.2 redirect all but one directory

I have this in my httpd.conf file: <VirtualHost IP.AD.DR.ESS:80> ServerName example.com Redirect Permanent / https://example.net/ </VirtualHost> This is successfully redirecting ...
FKEinternet's user avatar
9 votes
1 answer
39k views

IIS URL Rewrite Module Query String Parameters

Is it possible to use URL Rewrite to provide more complex query string functionality than the "Append query string" checkbox that it has? Specifically, is it possible to specify the keys for certain ...
Jason Kresowaty's user avatar
9 votes
3 answers
8k views

What URL should the browser display with this DNS configuration?

If I have the following records in the DNS: hostname Record Type address benmccormack.com A 216.10.244.61 www.benmccormack.com CNAME ...
Ben McCormack's user avatar
9 votes
4 answers
9k views

Why do I get a double trailing slash depending on where my RewriteRule is located?

I am using the following code to direct all www requests to non-www URLs: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] This ...
davekaro's user avatar
  • 193
9 votes
1 answer
28k views

Haproxy "use_backend" match order

I have a problem with HAProxy, it's a snippet of my haproxy.cfg below, acl url_a path_beg /a acl dom_eye hdr_dom(host) -i www.mydomin.com use_backend eye1 if dom_eye use_backend eye2 if dom_eye ...
glancesx's user avatar

1
2 3 4 5
43