dongzhaoshi8497 2013-11-13 20:05
浏览 92
已采纳

像htaccess这样的nginx重定向

I wanna remove from my url adress .php and redirect from example.com to www.example.com How can I this make in nginx? Thanks a lot!

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条回答 默认 最新

  • dongzhi5386 2013-11-13 20:11
    关注

    Try this:

    #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;
            ... 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?