phpcms配置支持https链接,超详细测试没有问题

今天没事把自己的门户网站申请的一个免费的CA证书,门户用的phpcms做的,phpcms更换https链接好像还很麻烦,因为链接里面都带了域名和http协议,所以改动起来地方挺多的,看了网上很多教程都不完善,自己从头到尾修改并记录下来了。

首先改动的就不用说了,caches/configs/下的system.php文件内所有的http批量替换为https

然后你模版里面的链接这个也不用说了,我比较同意,域名都是{APP_PATH},{JS_PATH},{IMG_PATH}这些常量,没有直接写死

再接着就是后台的设置-》站点管理-》修改网站域名为https打头的,这里可能会修改不了,别急,还是要改底层文件,phpcms/modules/admin/下的site.php文件,第45行

if (!empty($domain) && !preg_match('/http:\/\/(.+)\/$/i', $domain)) {
				showmessage(L('site_domain').L('site_domain_ex2'));
			}
改为
if (!empty($domain) && !preg_match('/(http|https):\/\/(.+)\/$/i', $domain)) {
				showmessage(L('site_domain').L('site_domain_ex2'));
			}

还没完,这个文件还有一处,128行

				if (!empty($domain) && !preg_match('/http:\/\/(.+)\/$/i', $domain)) {
					showmessage(L('site_domain').L('site_domain_ex2'));
				}
改为
				if (!empty($domain) && !preg_match('/(http|https):\/\/(.+)\/$/i', $domain)) {
					showmessage(L('site_domain').L('site_domain_ex2'));
				}

这两处都只是把http改成了https

还没完,我们接着改,phpcms/modules/content/templates/下的content_list.tpl.php文件97行

elseif(strpos($r['url'],'http://')!==false)
改成
elseif(strpos($r['url'],'http://')!==false || strpos($r['url'],'https://')!==false)

这个是从后台列表点击到文章页的问题

然后后台翻页也是有问题的,还要改翻页文件phpcms/libs/functions/下的global.func.php 第796行

$url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
改为
if(preg_match("https",$url)){
    $url = str_replace(array('https://','//','~'), array('~','/','https://'), $url);
}else{
    $url = str_replace(array('http://','//','~'), array('~','/','http://'), $url);
}

最后添加友情链接也会有问题,我们需要在友情链接的后台模版文件对JS的验证进行注释就可以了

找到phpcms/modules/link/templates/下的link_add.tpl.php和link_edit.tpl.php的

$("#link_url").formValidator({onshow:"<?php echo L("input").L('url')?>",onfocus:"<?php echo L("input").L('url')?>"}).inputValidator({min:1,onerror:"<?php echo L("input").L('url')?>"}).regexValidator({regexp:"^http(s?):\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&]*([^<>])*$",onerror:"<?php echo L('link_onerror')?>"})

这个JS的验证的http协议改成http(s?)即可

然后全站链接更新一遍,图片附件地址替换一遍,有时数量太大,你在后台更新了链接还是不行就要去数据库里面进行批量替换,然后在后台更新下全站缓存,栏目缓存,再生成一遍就行了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/419.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。