2015-12-14 112 views
0

我有一個從Ubuntu遷移的Ubuntu Nginx服務器上的Yii項目,現在表現很奇怪。 index.php (http://sitename/index.php/site/about)的網址正常,但http://sitename/site/about顯示首頁。 我試過了Yii的演示博客,並且在同一臺服務器上的兩個url(有和沒有index.php部分)都按預期工作。因此,NGINS服務器塊設置正確,並且在項目和博客演示中,Yi配置的UrlManager部分都是相同的。Yii重定向到index.php主頁

'urlManager' => array (
      'urlFormat' => 'path', 
      'showScriptName' => false, 
      'caseSensitive' => false, 

我應該在哪裏尋找問題的來源?

+0

你重寫轉換規則從Apache到Nginx? http://stackoverflow.com/questions/14927184/converting-htaccess-to-nginx-mod-rewrite – SiZE

+0

@SiZE是的,我試過'位置/ { try_files $ uri $ uri//index.php?args; }' 默認演示博客工作正常,但我的應用程序沒有。 在Apache中我有'RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule ^(。*)\?* $ index.php/$ 1 [L,QSA]' –

+0

也許這個wiki會幫助http://www.yiiframework.com/wiki/15/ – SiZE

回答

0

的問題是在Yii中應用程序配置:

'components' => array (
          'request' => array (
            'baseUrl' => 'http://sitename', 
          ),... 

卸下請求塊解決了這個問題。 但在Apache上是一種解決方法重寫規則RewriteRule ^(.​​*​)\?​*​​$ index.php/$1 [L,QSA]*​

0

請按照以下步驟從Yii中的URL中刪除index.php。

第一步:打開文件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 

編輯該文件名爲默認並將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