YII2.0中去除index.php後綴的方法

一、確保開啓了服務器的rewrite模塊,檢查httpd.conf

將LoadModule rewrite_module modules/mod_rewrite.so 前面的 ‘#’去掉

二、在YII2.0的根目錄下,添加.htaccess

提示,如果windows不允許創建該文件,可以藉助編輯器創建即可。

粘貼如下代碼:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

如果不能工作,嘗試下面的代碼:

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

沒有問題的話,它應該是可以的!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章