nginx:redirects
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
nginx:redirects [2017/02/22 12:04] – [Temporary Redirect] peter | nginx:redirects [2019/12/01 10:41] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== nginx - Redirects ====== | ||
- | |||
- | ===== Temporary Redirect ===== | ||
- | |||
- | <file bash> | ||
- | rewrite ^/ | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **Temporary redirects** (response status code 302 Found) are useful if a URL temporarily needs to be served from a different location. | ||
- | </ | ||
- | |||
- | Example: | ||
- | |||
- | <file bash> | ||
- | server { | ||
- | . . . | ||
- | server_name www.domain1.com; | ||
- | rewrite ^/$ http:// | ||
- | . . . | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | This redirect instructs the browser to direct all requests for www.domain1.com to www.domain2.com. | ||
- | |||
- | **redirect** matches regular expression patterns in parenthesis. | ||
- | |||
- | For example, if you wanted to temporarily redirect __every__ page within www.domain1.com to www.domain2.com, | ||
- | |||
- | <file bash> | ||
- | server { | ||
- | . . . | ||
- | server_name www.domain1.com; | ||
- | rewrite ^/(.*)$ http:// | ||
- | . . . | ||
- | } | ||
- | |||
- | server { | ||
- | . . . | ||
- | server_name www.domain2.com; | ||
- | . . . | ||
- | } | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | The **^/(.*)$** regular expression matches everything after the / in the URL. | ||
- | |||
- | For example, http:// | ||
- | </ | ||
- | |||
- | |||
- | ===== Permanent Redirect ===== | ||
- | |||
- | <file bash> | ||
- | rewrite ^/ | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **Permanent redirects** (response status code 301 Moved Permanently), | ||
- | </ | ||
nginx/redirects.1487765094.txt.gz · Last modified: 2020/07/15 09:30 (external edit)