2014-12-05 93 views
0

我正在學習Yii 2.0 Framework。我這樣配置urlManager:Yii 2.0 - 拒絕「index.php」訪問

'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 /網站/指數
  • 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規則直接指定的路線?


回答

0

嘗試增加這對你的規則(右下面的 「RewriteEngine敘述論」)

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