nginx 1.6.2
access
$uri
if
1)如果 存在文件 /Vhost/$http_host/$uri ,访问的是该文件
2)否则 如果 $uri 不是以 “/” 结尾 301 跳转到 $uri/
3)否则 如果 $uri 以 “/” 结尾 且 存在 /Cache/$http_host/$uri/index.html ,访问的是该文件
4)否则 指向 /index.php (ThinkPHP框架)
访问 http://www.a.com/robots.txt -> /Vhost/www.a.com/robots.txt
访问 http://a.com/robots.txt ->301 跳转 -> http://www.a.com/robots.txt
访问 http://www.c.com/sitemap.html -> /Vhost/www.c.com/sitemap.html
访问 http://www.d.com/game/ -> /Cache/www.d.com/game/index.html
访问 http://www.d.com/news/1000011 -> 301 跳转到 -> http://www.d.com/news/1000011/
访问 http://www.d.com/news/1000011/ -> /index.php (当该/Cache/www.d.com/news/1000011/index.html 不存在的时候)
访问 http://www.d.com/news/1000011/ -> /Cache/www.d.com/news/100011/index.html (当该/Cache/www.d.com/news/1000011/index.html 存在的时候)
server {
listen 80;
server_name wap wap.loc m.wap.loc wap.loc m.xxx.com game1.wap.loc game2.wap.loc game3.wap.loc;
location / {
root d:/wap_dev;
index index.html index.htm index.php;
try_files $uri /Vhost/$http_host/$uri /Cache/$http_host/$uri/index.html /index.php?s=$uri&$args;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
The above 1, 3, and 4 have been implemented, and 2 has not yet been implemented.
There is a typo in point 3) above, it is as follows. It has been modified, but sg has not changed
3)否则 如果 $uri 以 “/” 结尾 且 存在 /Cache/$http_host/$uri/index.html ,访问的是该文件
1) 如何才可以 不是 以/结尾且不是以.xml结尾且不是以.html .htm结尾的才跳转
Is it now a jump that ends with /, causing everything that ends with .xml and .html to also jump?
I wrote a paragraph myself, but failed:
rewrite ([^\/]|\.xml|\.html?)$ $uri/ permanent;
You need to use a named location starting with
@
to solve this problem.Because your rules are contradictory.
2 and 3 obviously cannot be satisfied at the same time.
should be changed to
is actually equivalent to