我想在没有index.phpCodeIgniter 的情况下访问我的URL .这是我的Blog控制器
class Blog extends CI_Controller {
public function index() {
echo 'hello world';
}
public function about() {
echo 'about page';
}
}
Run Code Online (Sandbox Code Playgroud)
现在我可以访问index via http://localhost/codeigniter/index.php/Blog,但我需要使用此URL访问它http://localhost/codeigniter/Blog.
注意
我从配置文件.htaccess文件中删除了index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Environment
Run Code Online (Sandbox Code Playgroud)
Windows,XAMPP,PHP 5.6.3版
要删除,请在与 site\xe2\x80\x99s 主 index.php 文件相同的文件夹中index.php创建一个文件。\n然后将以下代码添加到这个新创建的 .htaccess 文件中:.htaccess
<IfModule mod_rewrite.c>\n RewriteEngine On\n RewriteBase /\n\n # Removes index.php from ExpressionEngine URLs\n RewriteCond %{THE_REQUEST} ^GET.*index\\.php [NC]\n RewriteCond %{REQUEST_URI} !/system/.* [NC]\n RewriteRule (.*?)index\\.php/*(.*) /$1$2 [R=301,NE,L]\n\n # Directs all EE web requests through the site index file\n RewriteCond %{REQUEST_FILENAME} !-f\n RewriteCond %{REQUEST_FILENAME} !-d\n RewriteRule ^(.*)$ /index.php/$1 [L]\n</IfModule>\nRun Code Online (Sandbox Code Playgroud)\n\n此代码有两部分
\n1 - 删除 index.php
\n2 - 将所有站点请求重定向到索引文件。