【问题标题】:Yii 2.0 - deny "index.php" accessYii 2.0 - 拒绝“index.php”访问
【发布时间】:2015-02-03 04:40:26
【问题描述】:

我正在学习 Yii 2.0 框架。我这样配置 urlManager:

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '' => 'site',
            ],
        ],

SiteController 只有一个动作——actionIndex(默认一个)。我想要的是只能访问“mydomain.com”(所有其他请求都会导致 404 错误)。但现在我可以通过多种方式调用“站点/索引”操作:

  • mydomain.com
  • mydomain.com/site/index
  • mydomain.com/index.php
  • mydomain.com/index.php/site/index
  • mydomain.com/index.php?r=site/index

... 等等。我的 .htaccess 文件是:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if request dosn't start with web add it
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule (.*) $1

# if file or directory dosn't exists go to /web/index.php 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

那么我怎样才能限制所有这些并让我的应用程序仅使用 urlManager 规则中直接指定的路由?


【问题讨论】:

    标签: .htaccess yii2


    【解决方案1】:

    尝试将此添加到规则的顶部(在“RewriteEngine On”下方)

    RewriteCond %{THE_REQUEST} index\.php
    RewriteRule ^ / [L,R=404] 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-15
      • 2019-03-17
      • 2014-12-31
      • 1970-01-01
      • 2012-10-26
      • 2010-11-23
      • 2012-11-02
      • 1970-01-01
      相关资源
      最近更新 更多