0

我想从我的 url 地址中删除 .php 并从 example.com 重定向到 www.example.com 我怎样才能在 nginx 中制作?非常感谢!

server {
#listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www;
index index.php index.html index.htm;

server_name example.com;
    try_files $uri $uri/ /index.html;

}


location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}
}
4

1 回答 1

1

尝试这个:

#non-www to www solution

server {
        listen 80;
        server_name website.com;
        return 301 $scheme://www.website.com$request_uri;
}

server {
        listen 80;
        server_name www.website.com;
        ... 
}
于 2013-11-13T20:11:25.883 回答