TypechoJoeTheme

Dcr163的博客

统计

PHPCMS站点域名修改为/根目录或域名

2019-03-20
/
0 评论
/
1,125 阅读
/
正在检测是否收录...
03/20

相信不少朋友在使用phpcms的时候会碰到这个问题:生成今天文件的时候,会发现所有的url地址都是会携带一个完整的url域名,例如:http://xxx.com/abount/  这个地址,phpcms默认都是生成了带域名的url;
那这个对于多域名绑定一个网站的需求不是很友好,明明进入的是 http://xxx1.com 然后在页面点击其他地址的链接之后,又跳转到了 http://xxx.com/  这个域名之下(xxx这个是自己的域名)
下面给出解决方案:

一、修改文件:  phpcms/modules/admin/templates/setting.tpl.php
	在(大概58行)
		  
		    
		    
		    <input name="setconfig[attachment_stat]" value="1"  type="radio"  >     			<input  name="setconfig[attachment_stat]" value="0" type="radio"  >     
		  

	下行新增:
		    
		        不需要绑定站点域名
		        
		            <input name="setconfig[not_domain]" value="1"  type="radio"  >     
		            <input  name="setconfig[not_domain]" value="0" type="radio"  >    站点域名是否需要:http://xxx/com/ 这样的格式,否 则直接填写: /
		    二、修改文件:	phpcms/modules/admin/functions/global.func.php	     
	把(大概42行)
		in_array($k,array('js_path','css_path','img_path','attachment_stat','admin_log','gzip','errorlog','phpsso','phpsso_appid','phpsso_api_url','phpsso_auth_key','phpsso_version','connect_enable', 'upload_url','sina_akey', 'sina_skey', 'snda_enable', 'snda_status', 'snda_akey', 'snda_skey', 'qq_akey', 'qq_skey','qq_appid','qq_appkey','qq_callback','admin_url'))

	替换成:
		in_array($k,array('js_path','css_path','img_path','attachment_stat','admin_log','gzip','errorlog','phpsso','phpsso_appid','phpsso_api_url','phpsso_auth_key','phpsso_version','connect_enable', 'upload_url','sina_akey', 'sina_skey', 'snda_enable', 'snda_status', 'snda_akey', 'snda_skey', 'qq_akey', 'qq_skey','qq_appid','qq_appkey','qq_callback','admin_url','not_domain'))

三、修改文件:D:/WWW/waphm/phpcms/modules/admin/templates/site_edit.tpl.php
	把(大概11行)
		$("#domain").formValidator({onshow:"",onfocus:"",tipcss:{width:'300px'},empty:false}).inputValidator({onerror:""}).regexValidator({regexp:"http:////(.+)//$",onerror:""});
	替换成
		 //xj 190320
		$("#domain").formValidator({onshow:"",onfocus:"",tipcss:{width:'300px'},empty:false}).inputValidator({onerror:""}).regexValidator({regexp:"http:////(.+)//$",onerror:""});
        
 
四、修改文件:D:/WWW/waphm/phpcms/modules/admin/site.php
	把(大概128行)
        if (!empty($domain) && !preg_match('/http:////(.+)//$/i', $domain)) {
            showmessage(L('site_domain').L('site_domain_ex2'));
        }
        if (!empty($domain) && $data['domain'] != $domain && $this->db->get_one(array('domain'=>$domain), 'siteid')) {
            showmessage(L('site_domain').L('exists'));
        }		    
    替换成
    	$notDomain = pc_base::load_config('system', 'not_domain');
        if( $notDomain == 1 ) {
            $domain = '/';
        }else{
            if (!empty($domain) && !preg_match('/http:////(.+)//$/i', $domain)) {
                showmessage(L('site_domain').L('site_domain_ex2'));
            }
            if (!empty($domain) && $data['domain'] != $domain && $this->db->get_one(array('domain'=>$domain), 'siteid')) {
                showmessage(L('site_domain').L('exists'));
            }
        }  

    在(大概186行)
    	$setting['watermark_img'] = str_replace('statics/images/water/','',$setting['watermark_img']);
    下方新增
    	$not_domain = pc_base::load_config('system','not_domain');   

五、修改文件:D:\WWW\waphm\caches\configs\system.php
	在
		'alivulfix' => 'yes',
	下方新增
		'not_domain' => 0, // 不需要绑定站点域名 这样生成出来的静态地址 就不带 http://domain/dir/xx.html 而是 /dir/xx.html


按照上面的步骤即可,完成本次需求的实现,下面是使用的方法:

第一步:登录后台,在设置-基本设置里,把不需要绑定站点域名 选择:



第二步:站点设置,修改站点信息,把弹窗的 站点域名的输入框:修改为 即可



第三步:按照原来的方法直接生成静态文件即可,这时候会发现生成的文件的url都不带域名了。

这里再插一个问题,就是phpcms上传附件的时候存入数据库会带上域名一起保存,这样导致多站或网站使用https协议的时候导致页面排版错误,解决的办法就是,修改:/caches/configs/system.php 里的几个相关路径

//附件相关配置
'upload_path' => PHPCMS_PATH.'uploadfile/',
'upload_url' => '/uploadfile/', //附件路径
'attachment_stat' => '1',//是否记录附件使用状态 0 统计 1 统计, 注意: 本功能会加重服务器负担

'js_path' => '/statics/js/', //CDN JS
'css_path' => '/statics/css/', //CDN CSS
'img_path' => '/statics/images/', //CDN img
'app_path' => '/',//动态域名配置地址

朗读
赞(0)
版权属于:

Dcr163的博客

本文链接:

https://www.dcr163.cn/395.html(转载时请注明本文出处及文章链接)

评论 (0)

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

最新回复

  1. William Tardent
    2024-02-27
  2. Maryann Hamer
    2024-02-27
  3. Sanora Pantano
    2024-02-24
  4. aa
    2024-02-21
  5. Kassie Baum
    2024-01-28

标签云