gpt4 book ai didi

php - 在 CodeIgniter 3 中删除 index.php 的问题

转载 作者:可可西里 更新时间:2023-11-01 13:49:55 26 4
gpt4 key购买 nike

我想在 CodeIgniter 中不使用 index.php 访问我的 URL。这是我的 Blog Controller

class Blog extends CI_Controller {

public function index() {
echo 'hello world';
}

public function about() {
echo 'about page';
}
}

现在我可以通过 http://localhost/codeigniter/index.php/Blog 访问 index,但是我需要使用这个 URL http 访问它://localhost/codeigniter/Blog.

注意

我从配置文件中删除了 index.php.htaccess 文件

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Environment

Windows、XAMPP、PHP 5.6.3 版

最佳答案

How to remove index.php from url 已经被问了很多次了,这和 codeigniter 2 和 3 是一样的。

对于带有 Codeigniter Windows 的 Xampp

找到application/config/config.php

替换这个

$config['base_url'] = "";

有了这个

$config['base_url'] = "your-project-url";

替换这个

$config['index_page'] = "index.php"

有了这个

$config['index_page'] = ""

在主目录中创建名为 .htaccess 的文件

我使用下面的代码在 Windows 的 xampp 中对我来说效果很好。更多 htacces here

Options +FollowSymLinks
Options -Indexes

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

注意:确保您的 Controller 类似于示例 Welcome.php 而不是 welcome.php 如果删除 index.php,您可能还需要在 route.php 中创建新路由

关于php - 在 CodeIgniter 3 中删除 index.php 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30501756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com