如何从url中删除index.php [英] How can remove index.php from url
问题描述
当我鼠标悬停或点击锚链接时,它会显示
http:// localhost / code-testing / index .php / about-us。
我尝试了base_url()和site_url(),但结果是same.how可以删除'index.php'from the url?
- 谢谢。
已解决:
感谢大家的回答。我使用xampp,这个工作对我来说
code-testing / application / config / config.php
$ config ['base_url'] ='http:// localhost / code-testing /';
$ config ['index_page'] ='';
$ config ['uri_protocol'] ='REQUEST_URI';
代码测试/ .htaccess
RewriteEngine on
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule。* index.php / $ 0 [PT, L]
,然后下面的链接工作,不显示index.php >
< li>< a href =<?php echo base_url('home');?& ; / a>< / li>
< li>< a href =<?php echo base_url('about_us');?>>关于我们< / a>< / li&
< li>< a href =<?php echo base_url('contact');?>>联系我们< / a&
p>
1.在application / config.php文件中进行以下更改
$ config ['base_url'] ='http://'.$_SERVER ['SERVER_NAME']。'/您的Ci folder_name';
$ config ['index_page'] ='';
$ config ['uri_protocol'] ='AUTO';
2.使用以下代码在您的根目录中创建.htacces文件
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。首先,使用以下命令启动它:
a2enmod rewrite
修改/ etc / apache2 / sites-enabled / 000-default
将 AllowOverride无更改为全部允许覆盖。
iii。使用以下命令重新启动服务器:
sudo /etc/init.d/apache2 restart
when I mouse over or click on anchor links then it shows
http://localhost/code-testing/index.php/about-us.
I tried base_url() and site_url() too but the result is same.how can I remove that 'index.php' from the url ?
-Thanks.
Resolved:
Thank you everybody for your kind answers. I'm using xampp and this one worked for me
code-testing/application/config/config.php
$config['base_url']= 'http://localhost/code-testing/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
code-testing/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
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>
There are 3 steps to remove index.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.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.Enable rewrite mode
i. First, initiate it with the following command:
a2enmod rewrite
ii. Edit the file /etc/apache2/sites-enabled/000-default
change the AllowOverride None to AllowOverride All.
iii. Restart your server with the following command:
sudo /etc/init.d/apache2 restart
这篇关于如何从url中删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!