開啓重寫mod_rewrite.c php
能夠去掉URL地址裏面的入口文件index.php
,可是須要額外配置WEB服務器的重寫規則。apache
以Apache
爲例,須要在入口文件的同級添加.htaccess
文件(官方默認自帶了該文件),內容以下:bash
<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>
若是用的phpstudy
,規則以下:服務器
<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] </IfModule>
接下來就可使用下面的URL地址訪問了iview
http://tp5.com/index/index/index http://tp5.com/index/index/hello
若是你使用的apache
版本使用上面的方式沒法正常隱藏index.php
,能夠嘗試使用下面的方式配置.htaccess
文件:ui
<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>
若是是Nginx
環境的話,能夠在Nginx.conf
中添加:spa
location / { // …..省略部分代碼
if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } }