comparison xml/en/docs/faq_trailing_slash_redirect.xml @ 155:d8a53dda98a7

- Adding more faq's
author Andrey Alexeev <andrew@nginx.com>
date Wed, 26 Oct 2011 13:20:00 +0000
parents
children
comparison
equal deleted inserted replaced
154:dfc9d4338fef 155:d8a53dda98a7
1 <!DOCTYPE article SYSTEM "../../../dtd/article.dtd">
2
3 <article name="What is the right way to do a trailing slash
4 redirect for the requests without a
5 trailing slash in the URI?"
6 link="/en/docs/faq_trailing_slash_redirect.html"
7 lang="en">
8
9 <section>
10
11 <para>
12 <initial>Q:</initial>
13 What is the right way to do a trailing slash redirect for the
14 requests without a trailing slash in the URI?
15 </para>
16
17 <para>
18 <initial>A:</initial>
19 If the URI refers to a static file or a directory then nginx
20 will do the redirect automatically. If it's not a static
21 content and REQUEST_URI should be proxied to the backends,
22 the following configuration will work:
23 </para>
24
25 <para>
26 <example>
27 location ~* /[^/\.]+$ {
28 rewrite ^(.*)$ http://$http_host$1/ permanent;
29 }
30 </example>
31 </para>
32
33 <para>
34 However, a better way of doing that would be separating
35 static content and proxying:
36 </para>
37
38 <para>
39 <example>
40 location / {
41     index index.php;
42     try_files $uri $uri/ /index.php?$args;
43 }
44
45 location ~ (?<URL>^.*/[^/.]+$) {
46     return 301 http://$host$url/$is_args$args;
47 }
48
49 location ~ \.php$ {
50 ...
51 }
52 </example>
53 </para>
54
55 </section>
56
57 </article>