【问题标题】:url friendly in yii framework do not workyii 框架中的 url 友好不起作用
【发布时间】:2014-01-03 10:10:41
【问题描述】:

我正在使用 ubuntu 12.04,并且在 yii 框架中为 url 友好工作,我按照以下步骤操作:
步骤 1. 通过终端打开重写加载模块

-sudo a2enmod rewrite
 -sudo /etc/init.d/apache2 restart

在 apache 中加载的模块:

core mod_log_config mod_logio prefork http_core mod_so mod_alias mod_auth_basic 
mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user
mod_autoindex mod_cgi mod_deflate mod_dir mod_env mod_mime mod_negotiation mod_php5 
mod_reqtimeout mod_rewrite mod_setenvif mod_status

第 2 步:创建 .htaccess 并复制到受保护的项目中

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php
</IfModule>

第三步:在main.php中打开urlManager

'urlManager'=>array(
            'urlFormat'=>'path',    
            'showScriptName' => false,
            'urlSuffix'=>'.html',                   
            'rules'=>array(         
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),

但是我访问的时候有错误的url。

Not Found

The requested URL /news/news/index.html was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80

项目新闻和控制器新闻

非常感谢

【问题讨论】:

  • 你试过 URL /news/index.html 吗?如果它应该是 /news/news/ 你可能需要在你的 .htaccess 文件中变基到 /news/
  • Url 无法在 localhost 上运行?也许我会设置新的环境来运行

标签: yii


【解决方案1】:

.htaccess 需要与 index.php 位于同一文件夹中,并且服务器的文档根目录也需要指向该文件夹。您应该先尝试 /news/index.php?r=news/index 自己工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 2010-11-14
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多