2015-08-30 97 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。