2016-03-03 27 views
2

我想設置Yii2使用漂亮的URL。 爲了做到這一點,我配置了Yii2,並使用了apache的重寫模塊,以確保我們始終通過index.php的入口點進入。yii2漂亮的網址 - 瀏覽器找不到文件index.php

我對包含在.htaccess文件中的以下修改進行了修改yii-application/frontend/web /文件夾 - 包含index.php(高級yii2模板)的文件夾。對於這些修改,我遵循各種論壇上的指示。

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . index.php 

我也取得了yii2的配置如下變化,以激活漂亮的URL

$config = [ 
'components' => [ 
    'urlManager' => [ 
     'showScriptName' => false, 
     'enablePrettyUrl' => true, 
     'rules' => array(
      '<controller:\w+>/<id:\d+>' => '<controller>/view', 
      '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
      '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 
     ), 
    ], 
], 
]; 

注意Yii2運作良好之前我做了這些變化。

現在,如果我嘗試使用以下某個URL進行連接(如修改之前那樣),我會看到登錄頁面。導航不起作用,我會一直看到着陸頁。

http://localhost/frontend/ 
http://localhost/frontend/index.php 
http://localhost/frontend/index.php?r=site/about-us 
http://localhost/frontend/index.php?r=site/faq 

如果我嘗試使用下面的網址(如我曾經很網址是否正確配置)進行連接,我布勞爾顯示錯誤消息。

http://localhost/frontend/site/faq 
http://localhost/frontend/site/account 
http://localhost/frontend/site/index 

錯誤消息:

Not Found 
The requested URL /web/yii-application/frontend/web/index.php was not found on this server. 
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80 

但是,它看起來像路徑是正確的。 index.php文件實際上位於文件夾C:\ web \ yii-application \ frontend \ web \ index.php 我的瀏覽器怎麼沒有找到該文件?

感謝您的幫助

回答

1
+0

那裏沒有錯。在使用重寫之前或之後,我不需要「/ web」。 http:// localhost/frontend/local指向c:\ web \ yii-application \ frontend \ web \ –

+0

然後你可能會這樣做。 /web/yii-application/frontend/web/index.php,它試圖訪問一個奇怪的「網絡」文件夾內的index.php。 –

+0

發佈您用於執行此操作的虛擬代碼。 –