5

I have tried everything and I am close to giving up. Help please.

I've been trying to get rid of the index.php in codeigniter and have done every code that google has provided to put in the .htaccess.

Currently, I have this.

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

and this does work, but every time I submit a form, I get back this wonderful 302 error that is driving me crazy.

302 error

one of my submit function in my controller...the others are basically the same for other forms. I have already tried the refresh and the location method of redirecting, neither change anything. I do not believe this is the issue.

public function submitStory(){
  if (empty($this->user)) {
    redirect('/home/');
  }else{
    $this->story_model->writeStory();
     redirect('story/newChapterView/');
  }

}

my model is just inserting into the database

public function writeStory(){
  $this->title = strip_tags($this->input->post('wTitle'));  
  $this->date = time();
  $this->author = strip_tags($this->input->post('wAuthor'));    
  $this->type = strip_tags($this->input->post('wType'));    
  $this->db->insert('story_tbl', $this);
}

one of my forms, their pretty much just a standard codeigniter form

<?=form_open('story/submitStory', array('id' => 'newStory'));?>
    <p class="textBox"><label>Story Title: </label><input id="storyTitle" type="text" name="wTitle" autocomplete="off"  /></p>
    <p><label>Complete:</label><select class="drop" name="wcomplete" id="complete"><option value="no">no</option><option value="yes">yes</option></select></p>
    <p><label>Description:&nbsp;</label><textarea name="wDescription" id="wDescription" class="wDescription"></textarea><span id="discWarn">500 characters left</span></p>
    <p class="submit"><input type="submit" value="Submit Details" /></p>    
</form>
4

7 回答 7

1

最简单的一个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

如果它没有帮助,那么您应该检查 mod_rewrite 是否已启用。

于 2013-06-06T15:49:49.070 回答
0

Use this:

<IfModule mod_rewrite.c>
RewriteEngine On

#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
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
于 2013-06-06T01:29:28.640 回答
0

打开 config.php 并执行以下替换

$config['index_page'] = "index.php"
to
$config['index_page'] = ""

在某些情况下,uri_protocol 的默认设置无法正常工作。只需将 $config['uri_protocol'] ="AUTO" 替换为 $config['uri_protocol'] = "REQUEST_URI"

HTACCESS

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
于 2013-06-15T12:50:16.687 回答
0

确保更换

$config['index_page'] = 'index.php';

和....

$config['index_page'] = '';

在所有有这条线的线上....更改为...

RewriteRule ^(.*)$ index.php?/$1 [PT, L]
于 2013-06-14T08:11:38.273 回答
0

我在.htaccess文件中有相同的代码,它可以正常工作。

正如您所说,它发生在表单提交中,可能问题出在您的服务器配置上。重新检查您的服务器配置。

于 2013-06-09T19:01:22.410 回答
0

我认为这可以解决您的问题。

public function submitStory(){
  if (empty($this->user)) {
    redirect('/home/', 'location', 301);
  }else{
    $this->story_model->writeStory();
    redirect('story/newChapterView/', 'location', 301);
  }
}

redirect() 函数是这样的

redirect ($url, $method = 'location', $response = 302) {...};

默认响应代码是 302。所以你必须手动更改它。

ps第三个参数仅适用于'location'重定向,而不适用于 'refresh'

于 2013-06-14T12:37:41.817 回答
0

.htaccess为您的文件尝试这样的事情:

RewriteEngine On

#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L] 

之后?有助于index.php修复'No input file specified'错误

于 2013-06-09T04:06:28.863 回答