【问题标题】:Yii 404 error with urlmanager showscript to falseYii 404 错误,urlmanager showscript 为 false
【发布时间】:2013-09-21 07:16:26
【问题描述】:

我正在完成我在 Yii 应用程序上的工作,我想要更漂亮的 URL。我通过谷歌搜索网站和 Yii wiki 并按照手册进行操作。但是,我被困在无法从我的 URL 中隐藏 index.php 的地步。使用我的网址中的 index.php 它可以工作,该网站打开,没有它,它让我的服务器 404.

这是我的 main.config:

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

将“showScriptName”设置为 false 我得到 404。

这是我的 .htaccess

RewriteEngine on
RewriteBase /
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)

# otherwise forward it to index.php
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]

我目前正在使用 WAMP 在 localhost 上测试该站点。 Apache 上的 Mod_rewrite 正在运行。将 http.conf 更改为 Options Indexes FollowSymLinks Allow Override All。

我还缺少什么?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite yii


    【解决方案1】:

    对于那些苦苦挣扎的人!将 .htaccess 放到应用程序的根目录下,而不是放在受保护的文件夹中!!!

    【讨论】:

    • 我知道这是一个旧答案。但是你能解释更多关于这个的细节吗?因为这对我有用,但我不知道是什么使它起作用。谢谢。
    【解决方案2】:

    尝试添加:

    '' => 'site/index'
    

    到您的 urlManager 'rules' 数组。 逻辑是,Yii 无法将模式 '' 的请求与您定义的任何规则匹配。

    【讨论】:

      【解决方案3】:
          'urlManager' => array(
                  'urlFormat' => 'path',
                  'urlSuffix' => '.html',
                  'showScriptName' => false,
                  //  'caseSensitive'=>false, 
                  'rules' => array(
                       '<action>'=>'site/<action>',
         '<controller:\w+>/<id:\d+>' => '<controller>/view',
         '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
         '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                  ),
              ),
      

      在您的 .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
      

      在项目文件夹中上传您的 htaccess。

      【讨论】:

        【解决方案4】:

        在我的情况下,使用相同的设置会出现这两种情况:

        1. https://somedomain.com/action123 [失败,愚蠢的 404]
        2. https://somedomain.com/action123/[成功]

        问题是,最后的“/”符号(需要更多规则)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-11-11
          • 1970-01-01
          • 2018-05-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多