2017-12-10 04:40:56 2017次浏览 2条回答 0 悬赏 10 金钱

nginx设置:

server {
        listen       80;
        server_name  yii.com alias www.yii.com;
        location / {
            root   d:/web/www/yii/web/;
            index  index.html index.htm default.html default.htm index.php default.php app.php u.php;
			include        d:/web/www/yii/web/up-*.conf;

try_files $uri $uri/ /index.php$is_args$args;
        }
		autoindex off;
		include advanced_settings.conf;
		#include expires.conf;
		location ~* .*\/(attachment|attachments|uploadfiles|avatar)\/.*\.(php|php5|phps|asp|aspx|jsp)$ {
        deny all;
        }

        location ~ ^.+\.php {
            root           d:/web/www/yii/web/;
            fastcgi_pass   bakend;
            fastcgi_index  index.php;
			fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
			fastcgi_param  PATH_INFO $fastcgi_path_info;
			fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_path_info;
            include        fastcgi.conf;
        }
		}
#server yii.com end}

第二个:config下的web.php设置:

'components' => [
//rewrite路由(pathinfo)的形式访问  yii配置pathinfo
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [
                 '/' => '/site/index',  //这里
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                "<controller:\w+>/<action:\w+>"=>"<controller>/<action>",
            ],
        ],

目前url访问是这样的:

http://www.yii.com/index.php?r=site%2Findex
http://www.yii.com/index.php?r=site%2Fabout
http://www.yii.com/index.php?r=site%2Fcontact
http://www.yii.com/index.php?r=site%2Flogin

上面这些路径访问正常

想实现 像下面的url:

http://www.yii.com/
http://www.yii.com/about
http://www.yii.com/contact
http://www.yii.com/login

现在访问这些目录显示的页面内容都是首页的,不知道是哪里错了

  • 回答于 2017-12-10 11:08 举报

    rules里改成['/login' => '/site/login',],其他类似,index就不要动了

  • 回答于 2017-12-14 10:37 举报

     '/' => '/site/index',  //这里 rules 规则是错误的 yii2.0里 有默认的控制器和方法的

     'defaultRoute'=>'site',//默认路由
    
您需要登录后才可以回答。登录 | 立即注册
dazhaimen
实习生

dazhaimen

注册时间:2017-12-10
最后登录:2019-04-03
在线时长:0小时43分
  • 粉丝0
  • 金钱5
  • 威望0
  • 积分5

热门问题