Yii2.0 解決“the requested URL was not found on this server”問題
阿新 • • 發佈:2019-01-25
www 允許 路由 目錄 技術分享 span 錯誤 index scrip
在你下了 Yii 框架,配置完路由 urlManager 後,路由訪問頁面會報錯“the requested URL was not found on this server”,url類似於這種“https://www.cnblogs.com/site/index”。
‘urlManager‘ => [ ‘enablePrettyUrl‘ => true, ‘showScriptName‘ => false,//不顯示.php ‘suffix‘ => ‘.html‘,//後綴 ‘rules‘ => ["<controller:\w+>/<action:\w+>/<id:\d+>"=>"<controller>/<action>", "<controller:\w+>/<action:\w+>"=>"<controller>/<action>" ], ],
解決方法:
方法一:刪除項目下的 runtime 文件夾,然後強刷頁面。
方法二:在項目文件夾下面添加 “.htaccess”文件,內容如下:
Options +FollowSymLinks IndexIgnore*/* 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
或者這個也可以(兩個選一個)
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
添加以後再刷新頁面,就會發現可以正常訪問了,完美解決。
什麽是 .htaccess?
.htaccess是一個純文本文件,它裏面存放著Apache服務器配置相關的指令。
當我們使用apache部署一個網站代碼準備部署到網上的時候,我們手中的apache的httpd.conf大家肯定都知道。這是apache的配置文件,然而我們大多數的網站都是基於雲服務器來部署的,還有就是團隊協作開發的時候,我們很難直接修改公共的httpd.conf,這時 .htaccess就是httpd.conf的衍生品,它起著和httpd.conf相同的作用。
.htaccess 的作用?
-
URL重寫、自定義錯誤頁面
-
MIME類型配置
-
訪問權限控制等
-
主要體現在偽靜態的應用
-
圖片防盜鏈
-
自定義404錯誤頁面
-
阻止/允許特定IP/IP段
-
目錄瀏覽與主頁
-
禁止訪問指定文件類型
-
文件密碼保護
Yii2.0 解決“the requested URL was not found on this server”問題