简体   繁体   English

在Mandriva的CodeIgniter中从URL删除index.php

[英]Removing index.php from URL in CodeIgniter on Mandriva

I developed a project which uses CodeIgniter on Windows OS. 我开发了一个在Windows OS上使用CodeIgniter的项目。 The project works fine on XAMPP (Windows) and Linux hosting server (updated .htaccess on server to work). 该项目在XAMPP(Windows)和Linux托管服务器(服务器上更新的.htaccess可以正常工作)上正常运行。 I want to use Open Mandriva for development purpose. 我想将Open Mandriva用于开发目的。 If I run the controller using index.php, it works. 如果我使用index.php运行控制器,它将起作用。

I tried many .htaccess rules examples, links. 我尝试了许多.htaccess规则示例,链接。 But controller is not loading. 但是控制器未加载。

I tried: Cannot remove index.php from CodeIgniter URL , CodeIgniter removing index.php from url and this external link , and many other links. 我尝试过: 无法从CodeIgniter URL删除index.phpCodeIgniter从URL和此外部链接以及许多其他链接删除index.php

.htaccess code on Windows machine Windows机器上的.htaccess代码

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

.htaccess code on Linux hosting server Linux托管服务器上的.htaccess代码

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

Both are not working on Open Mandriva. 两者都无法在Open Mandriva上使用。

.htaccess path .htaccess路径

/srv/www/html/ci/

The page gives: 该页面提供:

404 error, and Object not found! 404错误,找不到对象!

The file system path to my project is 我项目的文件系统路径是

/srv/www/html/ci/application/controllers/ 

and on browser: 在浏览器上:

localhost/ci/branch 

Project works if I add index.php like 如果我像这样添加index.php,项目将正常工作

localhost/ci/index.php/branch

Is it having any relation with http server config? 它与http服务器配置有关系吗? Do I need to install any package. 我是否需要安装任何软件包。 Also I tried some commands for apache rewrite engine. 我也尝试了一些命令为Apache重写引擎。 But I get error as unknown command. 但是我收到错误作为未知命令。

Check if rewrite engine is enabled . 检查是否启用了重写引擎。

If not, enable rewrite engine and restart server. 如果不是,请启用重写引擎并重新启动服务器。

sudo a2enmod rewrite
sudo service apache2 restart

Go to

/etc/httpd/conf/httpd.conf - for Mandriva
/etc/apache2/apache2.conf  - for Ubuntu

Change AllowOverride None to AllowOverride All AllowOverride None更改为AllowOverride All

Code block: 代码块:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All

Restart Apache(httpd) service. 重新启动Apache(httpd)服务。

No changes required in config.php or anywhere else. 无需在config.php或其他任何地方进行更改。

.htaccess code: .htaccess代码:

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

Please try the following: 请尝试以下操作:

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

Then, in config.php : 然后,在config.php

$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

Please ensure that your .htaccess is located in the same directory as your index.php . 请确保您的.htaccessindex.php位于同一目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM