Forms 使用CakePHP将POST数据从www重定向到非www

Forms 使用CakePHP将POST数据从www重定向到非www,forms,cakephp,post,redirect,no-www,Forms,Cakephp,Post,Redirect,No Www,我正在使用CakePHP,我刚刚将此代码添加到app/webroot/.htaccess,以便将所有代码重定向到www.mywebsite.com <IfModule mod_rewrite.c> RewriteEngine On ##########added lines RewriteCond %{HTTP_HOST} !^www. [NC] RewriteCond %{HTTP_HOST} !^localhost [NC] RewriteRule

我正在使用CakePHP,我刚刚将此代码添加到app/webroot/.htaccess,以便将所有代码重定向到www.mywebsite.com

<IfModule mod_rewrite.c>
    RewriteEngine On

##########added lines 
   RewriteCond %{HTTP_HOST} !^www. [NC]
   RewriteCond %{HTTP_HOST} !^localhost [NC]
   RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
##########end of adding 


    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
**更新: 我还尝试了其他重定向,但没有结果:

$this->redirect(array('controller'=>'posts', 'action' => 'index'));

谢谢。

如果重定向成功,您不应该有问题,因为重定向是立即完成的(甚至在用户看到页面之前)。因此,文章总是从正确的url到正确的url。所以你的重定向可能不起作用!是的,他来自正确的URL,但我认为表单将数据发送到错误的URL。到最后。我不知道如何改变它。
$this->redirect(array('controller'=>'posts', 'action' => 'index'));