Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter中的URL未重定向_Php_Codeigniter - Fatal编程技术网

Php CodeIgniter中的URL未重定向

Php CodeIgniter中的URL未重定向,php,codeigniter,Php,Codeigniter,我有一个新的网站,我已经安装了codeigniter(最新版本)。 现在,为了进行测试,我在默认页面www.example.com中有一个表单。我已经在.htaccess的帮助下从url中删除了index.php。现在,如果我提交表单,我已经将其重定向到www.example.com/controller\u name/function\u name。该URL显示完美,正如我所写 <form action="<?php echo base_url(); ?>controller

我有一个新的网站,我已经安装了codeigniter(最新版本)。 现在,为了进行测试,我在默认页面www.example.com中有一个表单。我已经在.htaccess的帮助下从url中删除了index.php。现在,如果我提交表单,我已经将其重定向到www.example.com/controller\u name/function\u name。该URL显示完美,正如我所写

<form action="<?php echo base_url(); ?>controller_name/function_name" method="post" > 

对于我的设置,它还修改了htaccess以删除index.php,我必须将配置文件设置为

$config['index_page'] = '';
$config['base_url'] = '';
我正在使用请求URI:

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

在更改这些内容之前,我还未找到一个页面。试试这个,看看这是否对您有效。

问题在于您是如何删除index.php的


我确信,如果您试图发布到
,我的设置就是这样的:

config.php

$config['index_page'] = '';
$config['base_url'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = 'index.php';    
$config['base_url'] = '-your domain-';    
$config['url_suffix'] = '';
.htaccess

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

设置新的CodeIgniter安装对于第一次安装的人来说可能是个问题,但我可以向您保证,这比您想象的要容易

也许我为eleven2 provider上的CodeIgniter workink编写的教程可以帮助您:

请检查是否按照教程中的说明正确设置CodeIgniter;如果一切正常,我们必须找出php配置或其他方面的问题。

试试这个

<form action="<?php echo base_url(); ?>/controller_name/function_name" method="post" > 

使用CI 3.1.5时也有同样的问题。用这个设置修复了它

config.php

$config['index_page'] = '';
$config['base_url'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = 'index.php';    
$config['base_url'] = '-your domain-';    
$config['url_suffix'] = '';
.htaccess

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

将.htaccess文件放在“应用程序”文件夹外

您是否在
config/routes.php
中定义了路由?能否向我们展示相关代码?另外,您正在使用的.htaccess显示的是codeigniter生成的404页面,还是来自Web服务器的页面?是的,听起来您的htaccess设置错误,或者您需要更改$config['uri_protocol']。没有任何代码就可以说…@peacemaker-这是RewriteCond$1上的htaccess重写引擎^(index\.php |[Javascript/CSS/Image root Folder name(s)]| robots\.txt)RewriteRule^(.*)$/index.php/$1[L]这是正确的,但我认为如果您想使用CodeIgniter url助手,设置正确的基本url会更好;对于本地web服务器,可以将其设置为“http://www.your-site.com/”或“http://localhost/”。uri_协议在大多数情况下都可以像“自动”一样正常工作,它只需要为特定的web主机php配置进行更改。我更喜欢autodetect,因为它简化了从scm或其他自动方式进行部署。我想不是每个人都需要这个。url帮助程序和其他库使用自动检测的值,在我的经验中没有问题,例如
site\u url()
按预期工作。@complex857-它仍然不工作,抛出服务器的页面未找到错误。可能是您的Web服务器未读取.htaccess文件,如果您在apache上,检查
mod_rewrite
是否启用,以及
AccessFileName
AllowOverride
设置。我唯一能想到的是,您没有正确调用控制器。控制器的名称是什么?您是否使用了正确的拼写/大小写?如果您发布的是实际代码而不是“controller\u name/function\u name”,这会很有帮助。只有在您能够解释为什么您的修复程序能够真正解决问题的情况下,这样的回答才会真正有帮助。