如何从 url 中删除 index.php [英] How can remove index.php from url
问题描述
当我将鼠标悬停在或单击锚链接时,它会显示
when I mouse over or click on anchor links then it shows
http://localhost/code-testing/index.php/about-us.
我也试过 base_url() 和 site_url() 但结果是一样的.我怎样才能从 url 中删除那个index.php"?
I tried base_url() and site_url() too but the result is same.how can I remove that 'index.php' from the url ?
-谢谢.
已解决:
谢谢大家的热心回答.我正在使用 xampp,这个对我有用
Thank you everybody for your kind answers. I'm using xampp and this one worked for me
code-testing/application/config/config.php
code-testing/application/config/config.php
$config['base_url']= 'http://localhost/code-testing/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
代码测试/.htaccess
code-testing/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
然后以下链接工作而不会在 url 中显示index.php"
and the following links then worked without showing 'index.php' in the url
<li><a href="<?php echo base_url('home');?>">HOME</a></li>
<li><a href="<?php echo base_url('about_us');?>">About Us</a></li>
<li><a href="<?php echo base_url('contact');?>">Contact Us</a></li>
推荐答案
删除index.php有3个步骤
There are 3 steps to remove index.php
1.在 application/config.php 文件中进行以下更改
1.Make below changes in application/config.php file
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.使用下面的代码在你的根目录中制作 .htacces 文件
2.Make .htacces file in your root directory using below code
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
3.启用重写模式
我.首先,使用以下命令启动它:
i. First, initiate it with the following command:
a2enmod 重写
二.编辑文件/etc/apache2/sites-enabled/000-default
ii. Edit the file /etc/apache2/sites-enabled/000-default
将 AllowOverride None 更改为 AllowOverride All.
三.使用以下命令重新启动服务器:
iii. Restart your server with the following command:
sudo/etc/init.d/apache2 restart
这篇关于如何从 url 中删除 index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!