2015-08-30 98 views
0

我有我的htaccess和路由文件的問題。我想配置我的default_controller。Codeigniter htaccess和路由文件

$route['default_controller'] = 'fr/index'; 

我想使用URL重寫。使用htaccess文件刪除我的URL中的'index.php'。

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{REQUEST_URI} !/$ 
RewriteCond %{REQUEST_URI} !\. 
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?/page=$1 [QSA] 

RewriteCond $1 !^(index.php|assets/|robots.txt) 

RewriteRule ^(.*)$ index.php/$1 [L] 

當一方有效時,另一方不起作用。

你有一個想法,配置我的htaccess刪除'index.php',並添加一個default_controller routes.php?

我的控制器有一個子文件夾的應用程序/控制器/子/ myControllers.php

謝謝你的答案。

回答

1

這是我爲自己使用的.htaccess配置。它會刪除index.php並在域的開頭添加www。

RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} \s/+(.*?)/{2,}([^\s]*) 
RewriteRule^%1/%2 [R=302,L,NE] 

SetEnv no-gzip dont-vary 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)/{2,}[?\s] [NC] 
RewriteRule^/%1/ [L,R=301] 

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond %{REQUEST_URI} system|application 
RewriteRule ^(.*)$ index.php?/$1 [L] 

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

它也適用於我的子文件夾中的默認控制器。

+0

感謝您的回答。第12行存在問題。什麼標誌?我在OVH有一個共享主機。在本地主機上,我沒有配置問題,但沒有共享主機。 –

+0

你應該檢查你的服務器上的mod-rewrite配置。 –

+0

也編輯答案,固定線12. –

1

好吧,我找到了解決方案。我不知道爲什麼,但這個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] 

我試着靠近30個不同的htaccess。