php - How to allow 'http' only in the Access Rules array


In Yii, I am finding a way how to restrict the url that accesses my controller actions to 'http' only. I am thinking about how to get the url in a Yii way so that I can place my code in the 'expression' attribute of the array.




You can write a filter method in your base controller (components/Controller.php):

public function filterOnlyHttp($filterChain = null) {
    if (Yii::app()->request->isSecureConnection) {

It will redirect yourhttps:// tohttp:// requests. You can configure this filter for specific controller actions in a method in a controller:

public function filters() 
    return array(

If you generally want that redirect all yourhttps requests, then you could also put theif above (without theelse part) into theinit() method of your base controller incomponents/Controller.php.

People are also looking for solutions to the problem: mysql - how to show fixed images on pageload in php?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.