2016-04-14 322 views
0

我在我的項目中創建了名爲查詢的模塊。模塊的Yii網址管理器不起作用給404

如果我在線下運行 http://enqphp.intermesh.net/index.php?r=enquiry/Enquiryser/index/ 那麼這個URL是完美的。但我想這是短短的象 http://enqphp.intermesh.net/enquiry

對於這一點,我在URL manager部分做了一些修改,在我main.php文件:

return array(
    'caseSensitive' => true, 
     'urlSuffix' => '/', 
     'showScriptName' => false, 
     'urlFormat' => 'path', 
    'rules' => 
    array(
    '/' => array('site/index'), 

    /* my files starting from here */ 
    '<modules>/<controller:\w+>/<id:\d+>' => '<modules>/<controller>/view', '<modules>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<modules>/<controller>/<action>', 
    '<modules>/<controller:\w+>/<action:\w+>/*' => '<modules>/<controller>/<action>', 
    '/enquiry/'=>'enquiry/Enquiryser/index', 
    ), 
) 

但它不工作和投擲404頁未找到。 任何人都可以幫助我,我失蹤了嗎?

+0

檢查htaccess的天氣還要檢查改寫MOD是啓用或不? –

+0

對於'enquiry'模塊,生成的類名稱是什麼。意思是,當你創建了一個Enquiry.php時創建的'enquiry'模塊 - > Models,Controller&Views文件夾。正確嗎? –

+0

是的,控制器名稱是Enquiryser,我正在調用的操作是索引。 – user3381968

回答

0

你使用什麼網絡服務器? Nginx,Apache?

阿帕奇 要隱藏的index.php在你的網址,你可以在你的文檔根目錄或虛擬主機配置中添加了mod_rewrite指令.htaccess文件:

RewriteEngine on 

# prevent httpd from serving dotfiles (.htaccess, .svn, .git, etc.) 
RedirectMatch 403 /\..*$ 
# 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 

Nginx的 你必須已爲您配置服務器

location/{ 
     index index.html index.php; 
     try_files $uri $uri/ /index.php?$args; 
    } 
0

您可以手動配置yii\web\Application通過添加上述行:/path/to/your_app/common/config/main.php

'controllerMap' => [ 
    'abcd' => 'backend\controllers\BankController' 
], 

所以配置文件看喜歡:在服務器上存在 enter image description here