ThinkPHP CI codeignitor 框架 apache 重寫 url 隱藏index.php 服務器 報錯:Object not found! 多是.htaccess隱藏index.ph

開啓重寫mod_rewrite.c   php

隱藏index.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; } }
相關文章
相關標籤/搜索