我已經開始學習yii2了,我試圖做漂亮的網址,但是失敗了。我做了什麼: -漂亮的網址在yii2中不起作用
在配置/ web.php(我在下面編輯):
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Hide index.php
'showScriptName' => false,
// Use pretty URLs
'enablePrettyUrl' => true,
'rules' => [
],
然後我創建了一個.htaccess
文件,並把它放在根目錄(它有下面的代碼):
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
此外,我已經打開apache2.conf文件,改變這樣的:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All <! -- instead of none -->
Require all granted
</Directory>
我也檢查過該命令的變化:
grep -R AllowOverride /etc/apache2
它顯示一個如下:
/etc/apache2/apache2.conf: AllowOverride All <!-- It is showing that done -->
現在:
當我進入我的頁面通過:
它打開,當我將鼠標懸停在關於鏈接它顯示我:http://localhost/yii2/web/site/about(這表明相當的URL女傭)
但這個URL不起作用(說404發現)
我曾嘗試下面的帖子每個代碼:
How to access a controller with pretty url in Yii2
哪裏是你的文件系統上的應用程序?即其路徑。 – SaidbakR
很明顯,'.htaccess'設置不起作用。嘗試爲該目錄添加一個配置,而不是/除了'/ var/www /',即將其定義爲'var/www/html/yii2/web'或者最好設置你的yii的web目錄項目作爲虛擬主機。 – SaidbakR
是的,但我認爲,不知道,你必須刪除**斜線**,並且'.htaacess'應該放在你的應用程序的'web'目錄下。 – SaidbakR