Apache 重定向301时如何从htaccess中删除index.php-Codeigniter

Apache 重定向301时如何从htaccess中删除index.php-Codeigniter,apache,.htaccess,codeigniter,redirect,codeigniter-3,Apache,.htaccess,Codeigniter,Redirect,Codeigniter 3,当url类型为时,我在Codeigniter中遇到问题: example.gov.ar/news (without www and .gov) 我需要它重定向到: www.example.gob.ar/news (with www and .gob) 但它改变了方向 www.example.gob.ar/index.php/news 这是我的htaccess文件: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCon

当url类型为时,我在Codeigniter中遇到问题:

example.gov.ar/news (without www and .gov)
我需要它重定向到:

www.example.gob.ar/news (with www and .gob)
但它改变了方向

www.example.gob.ar/index.php/news
这是我的htaccess文件:

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

#non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

#.gov.ar to .gob.ar
RewriteCond %{http_host} ^example.gov.ar$ [OR]
RewriteCond %{http_host} ^www.example.gov.ar$ 
RewriteRule ^(.*)$ http://www.example.gob.ar/$1 [R=301,L]
注意:我的配置文件有$config['index_page']=''


提前感谢。

尝试切换规则的顺序

RewriteEngine on

#non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

#.gov.ar to .gob.ar
RewriteCond %{http_host} ^example.gov.ar$ [OR]
RewriteCond %{http_host} ^www.example.gov.ar$ 
RewriteRule ^(.*)$ http://www.example.gob.ar/$1 [R=301,L]

# Redirect to index.php internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
由.htaccess触发的外部重定向将根据所有规则重新评估,因此顺序很重要


按照更改后的顺序,外部重定向首先发生,因此只需将最终URL与第三条重写规则进行匹配,这样就不会在外部可见。

非常感谢!!天才!!