一、先說一下需求:
1、目錄結構:
2、原訪問路徑是:http://域名/index.php/admin/,想實現的效果是省略掉index.php,直接能用http://域名/admin/訪問到後臺。
二、解決方法:
通過URL重寫的方式可以達到這種效果,通常需要服務器開啓URL_REWRITE模塊才能支持。
打開public目錄下的.htaccess文件
.htaccess原來的內容如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
修改成:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>
保存就可以直接使用http://域名/admin/訪問了!