2013-06-06 58 views
5

我已經嘗試了一切,而且我已經接近放棄了。請幫助。codeigniter 302發現錯誤

我一直在努力擺脫codeigniter中的index.php,並且已經完成了谷歌已經提供的每個代碼,都放在.htaccess中。

目前,我有這個。

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] 

這個工作,但我每次提交表單的時候,我回來這美妙的302錯誤讓我發瘋了。

302 error

在我的控制器我提交功能的一個......其他基本上是爲其他形式相同。我已經嘗試了刷新和重定向的位置方法,但是沒有任何改變。我不相信這是問題。

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

}

我的模型只是插入數據庫

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); 
} 

我的形式之一,他們非常簡單,只是一個標準的笨形式

<?=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> 
+0

你假設的問題是與重定向 「AUTO」 - 但如果它只發生在表單上,​​也許檢查它們?什麼是爲表格生成的HTML?它要發佈什麼網址? – Stobor

+0

我在上面添加了一個表單。您發佈的網址的含義是什麼? – zazvorniki

回答

0

使用此:

<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> 
+0

如果我這樣做,我回來「沒有指定輸入文件。」 – zazvorniki

+0

顯然,有些事情是錯的。你把它放在正確的htaccess?在與index.php,系統和應用程序目錄相同的目錄中。 – edwardmp

+0

我把它放在正確的位置。這讓我瘋狂,因爲我已經做了這麼多次,而我用於這些項目的代碼並不適用於這個項目。我開始認爲這是一個Apache的問題,因爲我回來的頭輸出。 – zazvorniki

1

最簡單的一個:

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

如果沒有幫助,那麼你應該檢查mod_rewrite的啓用。

+0

之後主要養成它的醜陋頭腦,這個給了我404重定向以及刷新302錯誤的時候。我如何檢查是否啓用了mod_rewrite? – zazvorniki

+0

print_r(apache_get_modules()); –

+0

只是返回一個0,不知道如果這是一件好事或不.... – zazvorniki

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'錯誤

+0

這可以工作,但是當我提交表單時它仍然顯示服務器信息。 http://i1280.photobucket.com/albums/a485/Jessica_Sears/ScreenShot2013-06-09at84957AM_zps62049791.jpg – zazvorniki

0

我有相同的代碼在.htaccess文件和它的作品沒有任何問題。

正如你所說,它發生在表單提交,可能是你的服務器配置的問題。重新檢查你的服務器配置。

+0

你說的codeigniter文件夾或服務器本身ipage內的配置? – zazvorniki

+0

我正在談論服務器本身。 – sakibmoon

+0

我已經和ipage的人聊過,他們說一切都很好。除此之外,我無法訪問任何其他內容。 – zazvorniki

0

請務必將

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

與....

$config['index_page'] = ''; 

並就這一行....改變所有的行...

RewriteRule ^(.*)$ index.php?/$1 [PT, L] 
+0

謝謝你的回答!我已經完成了第一步,不幸的是rewriteRule發送給我一個500錯誤。 – zazvorniki

0

我認爲這可以解決您的問題。

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

重定向()函數是這個樣子

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

默認響應代碼是302。所以你必須手動改變它。

p.s.第三個參數僅適用於'位置'重定向,以及不'刷新'

+0

謝謝你的回答!不幸的是,我仍然得到這個標題。 http://s1280.photobucket.com/user/Jessica_Sears/media/ScreenShot2013-06-09at84957AM_zps62049791.jpg.html – zazvorniki

0

打開config.php文件,並做以下內容替換

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

在某些情況下,uri_protocol默認設置無法正常工作。 只需更換 $配置[ 'uri_protocol'] =通過 $配置[ '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] 
+0

謝謝,但我已經完成了這一步。這是導致我的問題。 – zazvorniki