从 CodeIgniter 3 中的 url 中删除 index.php
问题描述:
我正在 CodeIgniter 3 中做一个项目.我需要从 url 中删除 index.php
.为此,请帮助我获取 CodeIgniter 3 的 .htaccess
文件以及放置此文件的位置.
I am doing a project in CodeIgniter 3. I need to remove index.php
from url. For that help me to get .htaccess
file for CodeIgniter 3 and also where to place this file.
这是我的基本网址
http://cableandmedia.com/demo/
答
使用以下代码更新您的 htaccess 文件
Update your htaccess file with the below code
RewriteEngine On
RewriteBase /demo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
在配置文件中,请使用以下代码更改基本网址:-
and in config file, please change base url with below code:-
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;