yii2 urlManager 配置无效啊 [ 未指定版本 ]
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
按照官方配的呢 一设置就报错
共 17 个回答
-
正确的配置方法 是这样的
'components' => [ 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, ], ]
共 3 条回复 -
y284663247 回答于 2014-11-21 21:47 举报
设置完了之后,图片文件什么的样式变化了啊?
-
我是配置在web.php中的component里了:$config = [
'id' => 'basic', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'components' => [ 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ],
-
在 web 目录下添加 .htaccess
Options +FollowSymlinks IndexIgnore */* RewriteEngine On # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php
共 1 条回复crossey 觉得很赞 -
crisenchou 回答于 2016-05-13 14:41 举报
我发现这个答案现在还不是很完整,再补充一点好了,经过我的研究,我发现这玩意光靠框架本身是没有办法独自完成工作的,需要在服务器做配置
nginx配置的话需要加上if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php last; }
如果是apache服务器的话 楼上的仁兄已经给出了答案了
具体就是要忽视文件不存在的情况还有一点,通过阅读urlManager这个类的源码,enablePrettyUrl 这个参数是必须是true才可以
共 2 条回复crisenchou 回复于 2016-08-01 11:08 回复你看看apache的配置中有没有启用
LoadModule rewrite_module modules/mod_rewrite.so
要启用重写需要在apache的http.conf中 启用rewite mod -
下面我测试工作的, centos7+php5.6w+nginx1.63
yii2 advanced 的版本xxx.xxx.xxx 换成你的域名
主要是"location /" 里面的东西rewrite rules重要server { listen 80 default_server; #listen [::]:80 default_server; server_name xxx.xxx.xxx; root /usr/share/nginx/html/yii-application/frontend/web/; index index.php index.html index.htm; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { # Redirect everything that isn't a real file to index.php #try_files $uri $uri/ /index.php?$is_args$args; try_files $uri $uri/ /index.php?$args; #rewrite rules #autoindex on ; if (!-e $request_filename){ rewrite ^/(.*) /index.php?r=$1 last; } } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # With php5-fpm: fastcgi_pass unix:/run/php-fpm/php5-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } location /phpMyAdmin { alias /usr/share/nginx/html/phpMyAdmin; index index.php index.html index.htm; } location ~ /phpMyAdmin/.*\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$uri; include fastcgi_params; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
zjrman
注册时间:2014-09-25
最后登录:2014-09-27
在线时长:0小时53分
最后登录:2014-09-27
在线时长:0小时53分
- 粉丝0
- 金钱10
- 威望0
- 积分10