Yii使用index.php重定向到主页
我在ubuntunginx服务器上有一个Yii项目,它是从Apache迁移过来的,现在表现得很奇怪。带有Yii使用index.php重定向到主页,yii,Yii,我在ubuntunginx服务器上有一个Yii项目,它是从Apache迁移过来的,现在表现得很奇怪。带有index.php的URL(http://sitename/index.php/site/about)工作正常,但http://sitename/site/about显示主页。 我试过使用Yii附带的演示博客,在同一台服务器上,两个URL(带index.php部分和不带index.php部分)都能正常工作。因此,NGINS服务器块设置正确,Yi config的UrlManager部分的u部分在
index.php的URL(http://sitename/index.php/site/about)
工作正常,但http://sitename/site/about
显示主页。
我试过使用Yii附带的演示博客,在同一台服务器上,两个URL(带index.php部分和不带index.php部分)都能正常工作。因此,NGINS服务器块设置正确,Yi config的UrlManager部分的u部分在项目和博客演示中都是相同的
'urlManager' => array (
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
我应该在哪里查找问题源?问题在Yii应用程序配置中:
'components' => array (
'request' => array (
'baseUrl' => 'http://sitename',
),...
删除请求块解决了问题。
然而在Apache上有一个变通的重写规则
RewriteRule^(。*)\?*$ index.php/$1[L,QSA]*代码>请按照以下步骤从Yii中的URL中删除index.php
步骤1:打开protected/config/main.php文件,设置以下设置并保存
'urlManager' => array(
'showScriptName' => false,
步骤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
然后进入“站点可用”文件夹:
$ 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>
您是否将重写规则从apache转换为nginx?@SiZE是的,我已经尝试了location/{try\u files$uri$uri//index.php?$args;}
并且默认的演示博客工作正常,但我的应用程序没有。在apache中,我有RewriteCond%{REQUEST\u FILENAME}!-f RewriteCond%{REQUEST\u FILENAME}!-重写规则^(.\?*$index.php/$1[L,QSA]
也许这个维基会有所帮助
$ sudo service apache2 restart