0

我无法在 Yii 中配置路由项目是 3 天,都试图帮助......我有:

/var/www/ - 项目

/var/www/yii - yii 框架

./htaccess

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is http://localhost/begin/, use /begin/

RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

index.php 发现。

./var/www/protected/config/main.php

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(
              '/'=>'/view',
              '//'=>'/',
              '/'=>'/',
            ),
    ),

例如,当我输入 107.170.91.28/site/contact 时,会显示错误 404。服务器 107.170.91.28 的 URL 在本地服务器上。一切正常。如果我输入此 URL 107.170.91.28/index.php/site/contact 或 107.170.91.28/index.php?r=site/contact - 它可以工作。寻求帮助,因为我尝试了所有设置的方法。

4

1 回答 1

0

如果这仅在服务器上发生,则可能是因为您已将 Apache 配置为忽略服务器上的 .htaccess 指令,或者因为您没有加载/安装 Rewrite 模块

您可以通过更改 /etc/apache2/apache2.conf 来配置 apache conf 以打开(位置可能因操作系统而异,您当然也可以仅将其仅用于应用程序目录

<Directory>
...
        AllowOverride None
....
</Directory>

<Directory>
...
        AllowOverride All
....
</Directory>

启用重写模块,您可以执行(可能因操作系统而异)

a2enmod rewrite

之后重启apache2

/etc/init.d/apache2 restart

或者

service apache2 restart
于 2014-05-13T09:56:17.320 回答