I have a Yii project on Ubuntu Nginx server that is migrated from Apache and now behaving strange. URLs with index.php (http://sitename/index.php/site/about)
are working ok but http://sitename/site/about
displays homepage.
I've tried demo blog that comes with Yii and both urls(with and without index.php part) on same server works as expected. So NGINS server block is set up correctly and u part on UrlManager section of Yi config is the same on both project and a blog demo.
'urlManager' => array (
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
Where should I look for a problem source?
答案 0 :(得分:0)
问题出在Yii app config:
'components' => array (
'request' => array (
'baseUrl' => 'http://sitename',
),...
删除请求块解决了问题。
但是在Apache上是一种解决方法重写规则RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]*
答案 1 :(得分:0)
请按照以下步骤从Yii中的网址中删除index.php。
步骤1:打开文件protected / config / main.php并设置以下设置并保存。
'urlManager' => array(
'showScriptName' => false,
Step-2 .htaccess更改:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# 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
如果.htaccess无效,请按以下步骤启用它。
首先使用此命令启用重写:
$ sudo a2enmod rewrite
然后重启apache2:
$ sudo service apache2 restart
然后进入sites-available文件夹:
$ cd /etc/apache2/sites-available
编辑名为default的文件,并将AllowOverride none更改为AllowOverride All。有两行必须进行此更改。 这将使.htaccess在您的服务器中工作。
从此文件打开并编辑vim /etc/apache2/sites-available/000-default.conf
<Directory /var/www/html/>
AllowOverride all
Options None
Require all granted
</Directory>
最后重启apache2服务以应用所有更改
$ sudo service apache2 restart