使用.htaccess从url中删除index.php

时间:2014-11-10 07:37:11

标签: php .htaccess codeigniter

我正在使用Ubuntu。和服务器也是linex。我的框架是codeigniter。 我的.htaccess代码正在本地但不在服务器上运行.. 我使用.htaccess删除index.php 我的服务器网址与http://xx.xxx.xxx.xxx/foldername/index.php/signup类似。这里xx.xxx.xxx.xxx是http_host。

我的.htaccess代码是

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

我在$config['index_page'] = '';

中设置了配置

这个代码都是在localhost上进行的。但在服务器上它不工作。

请告诉我如何从url中删除index.php?

1 个答案:

答案 0 :(得分:1)

您需要拥有/foldername/.htaccess这样的内容:

RewriteEngine on

RewriteBase /foldername/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

然后在/foldername/application/config/config.php中你需要有这些配置设置:

$config['base_url']     = '';
$config['index_page']   = '';
$config['uri_protocol'] = 'AUTO';