harikrish
harikrish

Reputation: 2019

url rewriting in cakephp to add www in front of all url

i had a cakephp 2 application. i added ssl to it and there is one form in the site whos fields are populated using JavaScript, the form is submitted using JavaScript. After enabling security component, i am not able to submit the site. I know that the reason is that in this form i haven't used the form helper in some parts. i am sure that there is ways to by-pass security component for specific methods.I tried many but it does not work.

the following are the code.

app/controller/appcontroller.php

class AppController extends Controller {
      public $components = array('Session',
                                  'Auth'=> array(
                                  'authenticate' => `array('Form' =>array('fields'=>array('username' => 'email'))))`,
                                   'Acl'   ,

                                  'Email' => array('from' => '[email protected]',    'sendAs' => 'html',
                 )
                                ,'Security'=> array( 'allowedControllers'=>array('tests','live_tests'),'allowedActions'=>array('taketest','create_test'))
                                                                );
      public $helpers            =   array('Html', 'Form','Session','Js');

    function beforeFilter() {
    Security::setHash('md5');
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginError = 'Invalid Username or Password.';
    $this->Auth->authError = "You are not authorized to access.";
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
    $this->Auth->authorize = 'Actions';
    $this->Auth->actionPath = 'Controllers/';


            $this->Security->blackHoleCallback = 'forceSSL';
            $this->Security->requireSecure();

}   
  public function forceSSL() {
        $this->redirect('https://' . env('SERVER_NAME') . $this->here);
    }

}

i have forced https in appcontroller

the form that i want to use is in a controller called testcontroller and a method called test

Thank you for your time!

Upvotes: 0

Views: 260

Answers (1)

Colby Guyer
Colby Guyer

Reputation: 594

if you would like to try using apache config to do it. try this

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 2

Related Questions