如何正确配置URLmanager规则?

时间:2014-05-13 09:30:45

标签: php .htaccess yii yii-url-manager

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

/ var / www / - project

/ var / www / yii - yii framework

./ 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找到。

./无功/网络/保护/配置/ 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 - 它可以正常工作。 请求帮助,因为我尝试了所有方法。

1 个答案:

答案 0 :(得分:0)

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

您可以通过更改/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
相关问题