首页 文章

yii:如何在Yii配置SEO友好网址?

提问于
浏览
1

我通过yiic创建了一个应用程序 . 然后我试着制作一个SEO网址 . 我在[app root] /protected/config/main.php取消注释urlManager . 我在[app root] / . htaccess中添加了以下内容 .

RewriteEngine on目录或文件存在时,直接使用RewriteCond%!-f RewriteCond%! - 否则将其转发到index.php RewriteRule . 的index.php

当我浏览[app] / site / index时,我收到错误404 - 找不到对象 . 但如果我按[app] /index.php?r=site/index浏览,它会显示我的应用页面 . 我通过谷歌搜索跟踪了许多网站 . 但我得到了同样的错误 .

请帮我解决这个问题 .

3 回答

  • 1
    Try to use this :
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
    

    您可以使用Yii中的urlManager来获取自定义URL规则,而不是使用.htaccess . 请阅读urlManager以获取详细信息 . 我希望这篇文章也可能有助于你提出这个想法 . Controlling url in Yii: controller/action/id to /id

  • 1

    我自己找到了解决方案 . 1.在app / protected / config / main.php取消注释urlManager 2.在app /文件夹下创建.htaccess文件 . (重要:不在app / protected /文件夹下)3 . 将以下代码复制并粘贴到新的.htaccess文件中

    RewriteEngine on
    
    # 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
    

    那一切 . 谢谢你帮助我,每个人 .

  • 0

    Check out this article on URL rewriting in Yii

    此外,在您的配置中,将showScriptName设置为false

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

相关问题