.htaccess Index.php?301重定向后的url中
我已经把所有的内容从旧网站移到了新网站,现在我想用相同的URL将所有页面从旧网站重定向到新网站 例如: http://www.oldsite.net/en/newspage.html 到http://www.newsite.com/en/newspage.html http://www.oldsite.net/en/aboutus.html 到http://www.newsite.com/en/about.html Thsi是我的.htaccess: 这会重定向新站点上同一页面上的所有页面 但新网站有index.php吗?在重定向后的URL中。例如:.htaccess Index.php?301重定向后的url中,.htaccess,codeigniter,.htaccess,Codeigniter,我已经把所有的内容从旧网站移到了新网站,现在我想用相同的URL将所有页面从旧网站重定向到新网站 例如: http://www.oldsite.net/en/newspage.html 到http://www.newsite.com/en/newspage.html http://www.oldsite.net/en/aboutus.html 到http://www.newsite.com/en/about.html Thsi是我的.htaccess: 这会重定向新站点上同一页面上的所有页面
http://www.newsite.com/index.php?/en/about.html
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]
站点在codeigniter中开发
有人知道为什么会发生这种情况吗?正如@anubhava在评论中提到的,您的指令顺序错误。您的重定向需要在前端控制器之前进行。一般来说,外部重定向应该在内部重写之前进行。例如:
http://www.newsite.com/index.php?/en/about.html
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,然后被重定向。这就是重定向出错的原因。您的$config['index\u page']值是多少?$config['index\u page']='';只需将最后2行.htaccess移动到在线重写引擎的顶部或正下方即可。谢谢anubhava,但它不起作用: