像htaccess这样的nginx重定向

时间:2013-11-13 20:05:09

标签: php nginx

我想从我的网址地址.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;
}
}

1 个答案:

答案 0 :(得分: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;
        ... 
}
相关问题