2012-11-15 13 views
6

Magentoには、セキュリティが必要なページをリクエストするなど、優れた機能が組み込まれています。 httpでチェックアウトすると、httpsにリダイレクトされます。しかし、不足しているように見えるのは、誰かが安全である必要がないページをリクエストした場合などです。 https経由のカテゴリページでは、httpにリダイレクトする機能はないようです。誰かが要求した場合セキュリティで保護されていないマゼンタのページでhttpsをhttpにリダイレクト

だから:

https://www.mysite.com/mycategory

を、彼らは誰もがこれを達成するために管理

http://www.mysite.com/mycategory

に301リダイレクトされますか?

もしそうでなければ、HTTPSへのリダイレクトを行うマゼンタコアコードのビットの方向に私を指すことができる誰かが、それから解決策を思いつくためにそれから作業することができます。

答えて

7

ので、以下の方法

app/code/core/Mage/Core/Controller/Varien/Router/Standard.php::_checkShouldBeSecure() 
+1

乾杯はまさにそれを発見しました。 –

6

を見てみましょリッチのおかげで私は:: _ checkShouldBeSecure()

/アプリ/コード/コア/メイジ/コントローラ/ Varienにルータ/ Standard.phpこれを突き止め

Iは ELSEIF部分に

protected function _checkShouldBeSecure($request, $path='') 
{ 
    if (!Mage::isInstalled() || $request->getPost()) { 
     return; 
    } 

    if ($this->_shouldBeSecure($path) && !Mage::app()->getStore()->isCurrentlySecure()) { 
     $url = $this->_getCurrentSecureUrl($request); 

     Mage::app()->getFrontController()->getResponse() 
      ->setRedirect($url) 
      ->sendResponse(); 
     exit; 
    } elseif (!$this->_shouldBeSecure($path) && Mage::app()->getStore()->isCurrentlySecure()) { 
     $url = $this->_getCurrentUnsecureUrl($request); 

     Mage::app()->getFrontController()->getResponse() 
      ->setRedirect($url) 
      ->sendResponse(); 
     exit; 
    } 
} 

を追加(ローカルアドがそれを修正/アプリケーション/コードにコピーを作成)この関数を修正は、その後にこれを追加しました関数

protected function _getCurrentUnsecureUrl($request) 
{ 
    if ($alias = $request->getAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS)) { 
     return Mage::getBaseUrl('link', false).ltrim($alias, '/'); 
    } 

    return Mage::getBaseUrl('link', false).ltrim($request->getPathInfo(), '/'); 
} 
4

上記のヒントのためにありがとうございます。コアに過負荷をかけることなく、「Magentoのようなモジュール」にコードを統合しました。

作成するための3つのファイルだけがあります。

app/code/local/MyCompany/MyModule/Controller/Varien/Router/Standard.php 
app/code/local/MyCompany/MyModule/etc/config.xml 
app/etc/modules/MyCompany_MyModule.xml 

app/etc/modules/MyCompany_MyModule.xmlでは、次の興味のないものを貼り付けます。app/code/local/MyCompany/MyModule/etc/config.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <MyCompany_MyModule> 
      <active>true</active> 
      <codePool>local</codePool> 
     </MyCompany_MyModule> 
    </modules> 
</config> 

ルータ・コンフィギュレーションを貼り付けます。

<?xml version="1.0"?> 
<config> 
    <modules> 
     <MyCompany_MyModule> 
      <version>0.1.0</version> 
     </MyCompany_MyModule> 
    </modules> 
    <default> 
     <web> 
      <routers> 
       <standard> 
        <area>frontend</area> 
        <class>MyCompany_MyModule_Controller_Varien_Router_Standard</class> 
       </standard> 
      </routers> 
     </web> 
    </default> 
</config> 

はまた、 app/code/local/MyCompany/MyModule/Controller/Varien/Router/Standard.phpのロジックを実装する上:

<?php 

class MyCompany_MyModule_Controller_Varien_Router_Standard extends Mage_Core_Controller_Varien_Router_Standard { 

    protected function _checkShouldBeSecure($request, $path='') { 
     parent::_checkShouldBeSecure($request, $path); 

     if (!$this->_shouldBeSecure($path) && Mage::app()->getStore()->isCurrentlySecure()) { 
      $url = $this->_getCurrentUnsecureUrl($request); 

      Mage::app()->getFrontController()->getResponse() 
      ->setRedirect($url) 
      ->sendResponse(); 
      exit; 
     } 
    } 

    protected function _getCurrentUnsecureUrl($request) { 
     if ($alias = $request->getAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS)) { 
      return Mage::getBaseUrl('link', false).ltrim($alias, '/'); 
     } 

     return Mage::getBaseUrl('link', false).ltrim($request->getPathInfo(), '/'); 
    } 
} 

残念ながら、そこに問題を修正した観察する何のイベントはなかった...しかし、ルータをオーバーライドすることは(技術的に)置き換えるより(更新用)優れています。追加の知識については

1

は、httpsに強制する方法をカスタムモジュールのフロントエンドURLの問題を解決するには

チェックを次を通過してください。 httpの代わりに。モジュール作成者を使用してモジュールを作成した場合。あなたは間違いなく設定の下にあるコードを見つけるでしょう。アプリ/コード/(codepool)/(ネームスペース)/(ModuleNameの)は/ etc:XML

<admin> 
     <routers> 
     <[ModuleName]> 
      <use>admin</use> 
      <args> 
       <module>[NameSpace_ModuleName]</module> 
       <frontName>[frontName]</frontName> 
      </args> 
     </[ModuleName]> 
    </routers> 
</admin> 

は、httpではなくhttpsにリダイレクトの問題を解決するには、モジュールのconfig.xmlファイルのパスからのコードの上にコメントをする必要があります/config.xmlまたは、別の "frontName"とルーターを追加することもできます。例えば:上記のコードの管理URLを1として

<admin> 
     <routers> 
     <[ModuleName]> 
      <use>admin</use> 
      <args> 
       <module>[NameSpace_ModuleName]</module> 
       <frontName>[frontName]</frontName> 
      </args> 
     </[ModuleName]> 
    </routers> 
</admin> 

<frontend> 
     <routers> 
     <[ModuleName]> 
      <use>standard</use> 
      <args> 
       <module>[NameSpace_ModuleName]</module> 
       <frontName>[frontName1]</frontName> 
      </args> 
     </[ModuleName]> 
    </routers> 
</frontend> 

http://yourdomain.com/index.php/frontName/adminhtml_moduleName/になり、同様にフロントエンドのURLは次のようになります。私はコンテンツの上に、あなたの役に立つことを願うhttp://yourdomain.com/index.php/frontName1

1

上記のコードは、要求からのクエリ文字列を取り除きます。両方の関数を変更して、リダイレクト前にリクエストに追加する必要があります。

は、下記を参照してください:豊富な

$querystring = $_SERVER['QUERY_STRING']; 

return Mage::getBaseUrl('link', false).ltrim($request->getPathInfo(), '/').($querystring ? '?'.$querystring : ''); 
関連する問題