2012-04-13 105 views
0

我做了什麼,它是在htaccess的說:笨不會重定向URL

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

我把上面的,這樣我就可以做到這一點:

http://localhost/Speakom2/Home/index 

相反的:

http://localhost/Speakom2/index.php/Home/index 

但它不工作......我得到404錯誤..如何解決這個問題,所以它的工作原理?!?

控制器:

class Home extends CI_Controller { 

public function Index() 
{ 
    $this->load->view('welcome_message'); 
} 

}

的htaccess:

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

[笨htaccess的子文件夾的問題]的可能重複(http://stackoverflow.com/questions/7527491/codeigniter-htaccess-subfolder-problem) – Ben 2012-04-13 07:08:21

回答

1

當你在本地主機上運行Web根/localhost/mysite/但在真實主機的根/mysite: so localhost使用:

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

注意,如果沒有/

+0

看到更新...... – 2012-04-13 07:14:49

+0

niCE回答,NICE EXPLANATION – 2012-11-01 09:23:22

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

的index.php //這是.htaccess文件只需更換它 RewriteEngine敘述在 RewriteBase //

#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_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

#When your application folder isn't in the system folder 
#This snippet prevents user access to the application folder 
#Submitted by: Fabdrol 
#Rename 'application' to your applications folder name. 
RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

#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] 

1

確保您的.htaccess文件在Speakom2文件夾(Codei gniter根目錄)。而改變這一

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

您的解決方案可行......謝謝 – 2012-04-13 07:17:13