分享

写回答

发帖

[经验] 不违反godaddy协议完美去除免费空间广告的思路及实现方法

GoDaddy GoDaddy 2311 人阅读 | 4 人回复

发表于 2011-6-2 18:10:28 | 显示全部楼层 |阅读模式

如果你够细心,你会发现访问空间根目录中的 missing.html 404错误文件时没有广告,有什么想法没,将空间所有访问地址都转到 missing.html 文件,再让 missing.html 这个文件具有执行 php 代码的能力而去调用对应的文件,是不是这些转到 missing.html 的地址都没有广告了呢,惊讶了吧,此举没有任何去除广告的代码,你不必担心违反GODADDY协议,更重要的是该方法确实可行而并非设想

使用条件:
1.对程序结构了解
2.有简单编程能力


根目录的.htaccess文件内容
  1. #设missing.html为第一个默认首页
  2. DirectoryIndex missing.html index.html index.htm index.php

  3. #让missing.html具有执行PHP代码的能力,如果访问页面时弹出下载对话框请注释掉
  4. DefaultType application/x-httpd-php
  5. AddHandler x-httpd-php5 .php .html

  6. <IfModule mod_rewrite.c>
  7. RewriteEngine On
  8. #设置.htaccess的目录,根据服务器配置选择是否需要此行
  9. RewriteBase /
  10. RewriteCond %{HTTP_HOST} ^domain.com [NC]
  11. RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
  12. RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
  13. #将所有php,htm,html文件重写到missing.html
  14. RewriteRule ^(.*)\.php|\.htm|\.html(.*)$ missing.html$2
  15. </IfModule>
复制代码
根目录的missing.html文件内容
  1. <?php
  2. function MYpath($path=null){ /*获取服务器绝对路径*/
  3.         if (!empty($path)) {
  4.                 if (strpos($path,'\\')!==false) {
  5.                         return substr($path,0,strrpos($path,'\\')).'/';
  6.                 } elseif (strpos($path,'/')!==false) {
  7.                         return substr($path,0,strrpos($path,'/')).'/';
  8.                 }
  9.         }
  10.         return './';
  11. }
  12. function MYext($url){ /*获取文件扩展名*/
  13.   $path=parse_url($url);
  14.   $str=explode('.',$path['path']);
  15.   return $str[1];
  16. }

  17. define('W_R_P',MYpath(__FILE__));
  18. $myurl = $_SERVER['REQUEST_URI']; /*完整url*/
  19. $path = pathinfo($myurl);

  20. /*获取实际文件名*/
  21. if($path['extension']=='html' && strpos($path['filename'],'-')){ /*如果启用了伪静态,根据实际情况修改*/
  22.   $myfiles = explode('-',$path['filename']);
  23.         $myfile = str_replace(array('//','\\'),array('/',''),$_SERVER['DOCUMENT_ROOT'].$path['dirname'].'/'.$myfiles[0].'.php');
  24. }else{ /*如果没有启用伪静态,根据实际情况修改*/
  25.   $myfile = str_replace(array('//','\\'),array('/',''),$_SERVER['DOCUMENT_ROOT'].$path['dirname'].'/'.$path['filename'].'.'.MYext($myurl));
  26.         if(strpos($myfile,'?')){
  27.           $myfiles = explode('?',$myfile);
  28.                 $myfile = $myfiles[0];
  29.         }
  30. }

  31. /*重新定义系统变量PHP_SELF*/
  32. $pathdirfile = pathinfo($_SERVER['REQUEST_URI']);
  33. if(strpos($pathdirfile['filename'],'.php')){$path3=explode('.php',$pathdirfile['filename']);$pathdirfile['filename']=$path3[0];}
  34. $php_self = $pathdirfile['filename'] ? str_replace(array('//','\\'),array('/',''),$pathdirfile['dirname'].'/'.$pathdirfile['filename'].'.php') : str_replace(array('//','\\'),array('/',''),$pathdirfile['dirname']);
  35. $_SERVER['PHP_SELF'] = $php_self;

  36. if(strpos($myurl,'adminjob')){ /*如果路径中包含adminjob则认为是管理后台*/
  37.   require_once('admin.php');
  38. }elseif(substr($myfile,-1)=='.'){ /*如果文件名为小数点则认为没有文件名*/
  39.   require_once('index.php');
  40. }elseif(file_exists($myfile)){ /*如果文件存在则正常执行*/
  41.         require_once($myfile);
  42. }else{ /*如果文件不存在则调用首页,访问所有页面都显示首页则说明没有正常获取到文件名*/
  43.   require_once('index.php');
  44. }
  45. ?>
复制代码
以上为本人对针对phpwind论坛程序所做的成功案例,另外对ecshop商店程序也使用成功,missing.html文件须要配合你的程序来使用
祝大家成功

回答|共 4 个

jzw001

发表于 2011-6-2 18:22:52 | 显示全部楼层

html后缀的不是直接返回,不执行的吗?
不过楼主做成功了,的确强大。
回复 支持 反对

使用道具 举报

stonys

发表于 2011-6-2 18:24:24 | 显示全部楼层

高手呀。。感谢分享
回复 支持 反对

使用道具 举报

cryz

发表于 2011-6-2 19:11:58 | 显示全部楼层

原帖由 jzw001 于 2011-6-2 06:22 PM 发表
html后缀的不是直接返回,不执行的吗?
不过楼主做成功了,的确强大。

也可以执行,不过要设置
回复 支持 反对

使用道具 举报

lwbo1987

发表于 2011-6-3 09:43:27 | 显示全部楼层

楼主很强大,支持!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则