Magento URL中的uenc参数说明

浏览器查看magento 的html源文件,就会发现有很多如下的链接中带有uenc参数

catalog/product_compare/index/items/45/uenc/a———-od–MuY29tLw,,/

那么Magento URL中的uenc参数是干什么的?

//Mage_Core_Controller_Varien_Action 文件中
const PARAM_NAME_URL_ENCODED
    protected function _getRefererUrl()
    {
        refererUrl =this->getRequest()->getServer('HTTP_REFERER');
        if (url =this->getRequest()->getParam(self::PARAM_NAME_REFERER_URL)) {
            refererUrl =url;
        }
        if (url =this->getRequest()->getParam(self::PARAM_NAME_BASE64_URL)) {
            refererUrl = Mage::helper('core')->urlDecodeAndEscape(url);
        }
        if (url =this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
            refererUrl = Mage::helper('core')->urlDecodeAndEscape(url);
        }

        if (!this->_isUrlInternal(refererUrl)) {
            refererUrl = Mage::app()->getStore()->getBaseUrl();
        }
        returnrefererUrl;
    }

进入这个文件 Mage_Core_Helper_Abstract 不难看出这个uenc参数保存的是当前页面的url的base64值,作用是进行某些操作后能 返回uenc对应的链接。

Magento2自定义路由实现URL重写

最近在写个magento2的blog插件,需要实现URL伪静态。
更多可以参考magento2自带的CMS 模块
代码如下:

先定义di文件,app/code/Mageoo/MyBlog/etc/frontend/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\App\RouterList">
        <arguments>
            <argument name="routerList" xsi:type="array">
                <item name="cms" xsi:type="array">
                    <item name="class" xsi:type="string">Mageoo\MyBlog\Controller\Router</item>
                    <item name="disable" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="string">70</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

di.xml配置对应的Router class文件 app/code/Mageoo/MyBlog/Controller/Router.php

    public function match(\Magento\Framework\App\RequestInterface request)
    {identifier = trim(request->getPathInfo(), '/');condition = new \Magento\Framework\DataObject(['identifier' => identifier, 'continue' => true]);this->_eventManager->dispatch(
            'cms_controller_router_match_before',
            ['router' => this, 'condition' =>condition]
        );
        identifier =condition->getIdentifier();

        if (condition->getRedirectUrl()) {this->_response->setRedirect(condition->getRedirectUrl());request->setDispatched(true);
            return this->actionFactory->create('Magento\Framework\App\Action\Redirect');
        }

        if (!condition->getContinue()) {
            return null;
        }

        //identifier 获取到了identifier 后,就可以查找具体blogid,然后把参数分发到具体的Action处理。

        request->setModuleName('myblog')->setControllerName('index')->setActionName('index')->setParam('blogid',blogid);
        request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS,identifier);

        return $this->actionFactory->create('Magento\Framework\App\Action\Forward');
    }

Magento CDN加速Cloudflare开启https后无限重定向问题

Cloudflare是用的很多的免费CDN服务商,尤其是面向国外电商的网站。Cloudflare的CDN可以隐藏服务器IP,又提供免费的https服务,尤其吸引着一部分的人,特别是一些特殊的Magento网站,这里就不多说了,这里说的是Magento的系统怎么启用Cloudflare的免费https。 当Magento网站完成Cloudflare的接入后,Cloudflare就会给当前的域名签发ssl证书,这时候用 https://www.域名.com 就可以访问到magento的网站的。当然,这也只是能访问到,会出现非https加密连接被拒绝的错误。 嗯,到这里有感觉了,于是马上到magento后台开启https安全连接,然而到了这里才是本文提到的问题的开始,你会发现访问网站会无限重定向而over…

Cloudflare https和http都请求magento服务器80端口的情况

set ishttps "off";

if (http_x_forwarded_proto = "https") {
    set ishttps "on";
}
location ~ [^/]\.php(/|){

    try_files uri =404;
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_param HTTPSishttps;
}

上面的代码放到listen 80端口的service里面,大概意思是请求的http_x_forwarded_proto是https的,向php后端传递HTTPS=on的值。
因为magento里面是用

//_SERVER['HTTPS']this-&gt;getServer('HTTPS') == 'on'

来判断https的。
写的有点匆忙,有时间再整理一篇关于magento https无限重定向在 各种环境下的解决办法的文章出来。

清除mysql的log日志和关闭bin-log日记

如果在my.cnf中开启

log-bin=mysql-bin

mysql就会记录log,但是时间一长就会产生大量的日志,很占空间

117M    mysql-bin.000030
478M    mysql-bin.000031
1.1G    mysql-bin.000032
963M    mysql-bin.000033
4.0K    mysql-bin.000034
1.1G    mysql-bin.000035
1.1G    mysql-bin.000036
30M     mysql-bin.000037
8.0K    mysql-bin.index

排除用脚本自动删除日志的方法,有2个方法可以清理这些东西

第一:关闭log-bin=mysql-bin

直接在my.cnf中注释掉这一行

#log-bin=mysql-bin

第二:使用命令清空

先查看下log

mysql> show master logs;
+------------------+------------+
| Log_name         | File_size  |
+------------------+------------+
| mysql-bin.000001 |      25818 |
| mysql-bin.000002 | 1073764880 |
| mysql-bin.000003 | 1073744915 |
| mysql-bin.000004 | 1073745502 |
| mysql-bin.000005 | 1073742693 |
| mysql-bin.000006 | 1073743058 |
| mysql-bin.000007 |  155022099 |
+------------------+------------+
7 rows in set (0.01 sec)

然后刷新

mysql> reset master;
Query OK, 0 rows affected, 36 warnings (0.05 sec)

再看下

mysql> show master logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       107 |
+------------------+-----------+
1 row in set (0.00 sec)

这样只会保留最新的日志文件了,其他的就清空了~