2017-07-25 108 views
0

我已经将所有内容从旧网站移动到新网站,现在我想301将所有网页从旧网站重定向到新网站,具有相同的URL。Index.php?在301重定向

实施例:

  • http://www.oldsite.net/en/newspage.htmlhttp://www.newsite.com/en/newspage.html

  • http://www.oldsite.net/en/aboutus.htmlhttp://www.newsite.com/en/about.html

Thsi是我.htaccess

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 


RewriteCond %{HTTP_HOST} ^www\.olddoamin\.net$ [NC] 
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L] 

而这种重定向新的网站在同一页上的所有网页,

但新的网站重定向后,在URL index.php?。例如:

http://www.newsite.com/index.php?/en/about.html 

网站是在codeigniter中开发的。

任何人都有一个想法,为什么发生这种情况?

+0

什么是你的'$ config ['index_page']'值? – Nawin

+0

$ config ['index_page'] =''; –

+2

只需将'.htaccess'的最后两行移动到顶部或正下方'RewriteEngine On'行即可。 – anubhava

回答

1

正如@anubhava在评论中提到的那样,您的指令的顺序是错误的。您的重定向需要在之前前控制器。 (作为一般规则,外部重定向应该总是前内部重写去。)例如:

RewriteCond %{HTTP_HOST} ^www\.olddoamin\.net$ [NC] 
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L] 

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

但是,你需要在测试前先清除浏览器缓存,作为较早(错误)301重定向将被浏览器强制缓存。

如果您在前端控制器之后重定向,则请求首先被重写为/index.php?/en/about.html,然后重定向。因此,为什么重定向会搞砸。