编码htaccess和路由文件


Codeigniter htaccess and routes files

我有一个问题与我的htaccess和路由文件。我想配置我的default_controller。

$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到路由。php吗?

我的控制器位于application/controllers/subfolder/myControllers.php的子文件夹

谢谢你的回答

这是我自己使用的。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]

也适用于子文件夹中的默认控制器

好了,我找到解决方案了。我不知道为什么,但是这个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。