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

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)