Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
htaccessrewrite:忽略语言代码,将index.php添加到url中而不进行更改_Php_Apache_.htaccess_Codeigniter_Mod Rewrite - Fatal编程技术网

htaccessrewrite:忽略语言代码,将index.php添加到url中而不进行更改

htaccessrewrite:忽略语言代码,将index.php添加到url中而不进行更改,php,apache,.htaccess,codeigniter,mod-rewrite,Php,Apache,.htaccess,Codeigniter,Mod Rewrite,我使用以下规则将带有语言代码(en、fr等)的url重定向到不带它的url,但在任何段之前添加index.php。但它并没有像预期的那样起作用 我需要index.php,因为我使用的是php框架codeigniter 用户访问的url: 他们实际去的地方: 如果我使用以下规则,重定向可以工作,但我不想更改url RewriteRule ^(en|fr)/(.*)$ http://www.example.com/index.php/index.php/$2 [NC,L] url中不需要in

我使用以下规则将带有语言代码(en、fr等)的url重定向到不带它的url,但在任何段之前添加index.php。但它并没有像预期的那样起作用

我需要index.php,因为我使用的是php框架codeigniter

用户访问的url:

他们实际去的地方:

如果我使用以下规则,重定向可以工作,但我不想更改url

RewriteRule ^(en|fr)/(.*)$ http://www.example.com/index.php/index.php/$2 [NC,L] 

url中不需要index.php。 但是,这取决于您的配置服务器

在大多数情况下,我的团队和我使用以下htaccess和 我们编辑配置文件(config.php)以设置 将索引页添加到“”,因为您的htaccess完全知道如何做这些工作。 但是,对于路由,让codeigniter为您这样做

#.htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
RewriteRule ^(.*)$ index.php/$1 [L]
对于您的应用程序/config/config.php文件

最后,您应该设置一些基本路线:

// application/config/config.php file
$route['default_controller'] = 'Home';
// other routes here
$route['^(en|fr)/(.+)$'] = "$2";
$route['^(en|fr)$'] = $route['default_controller'];
注意,路线的位置很重要。(精确到最小)

我鼓励您阅读和并查看(毫无问题地使用codeigniter 2和3)


我希望它能帮助你和其他人理解路线。

也许会有帮助:我试过(a-zA-Z{2})/(*)但不起作用,因为这是一个未回答的问题:你还在寻找这个问题的解决方案吗?如果是这样的话,你能澄清你所说的“如果我使用以下规则,重定向是有效的,但我不想更改url”是什么意思吗?
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = ''; // at the place of : 'index.php';
// application/config/config.php file
$route['default_controller'] = 'Home';
// other routes here
$route['^(en|fr)/(.+)$'] = "$2";
$route['^(en|fr)$'] = $route['default_controller'];