|
|
如果你够细心,你会发现访问空间根目录中的 missing.html 404错误文件时没有广告,有什么想法没,将空间所有访问地址都转到 missing.html 文件,再让 missing.html 这个文件具有执行 php 代码的能力而去调用对应的文件,是不是这些转到 missing.html 的地址都没有广告了呢,惊讶了吧,此举没有任何去除广告的代码,你不必担心违反GODADDY协议,更重要的是该方法确实可行而并非设想
使用条件:
1.对程序结构了解
2.有简单编程能力
根目录的.htaccess文件内容- #设missing.html为第一个默认首页
- DirectoryIndex missing.html index.html index.htm index.php
- #让missing.html具有执行PHP代码的能力,如果访问页面时弹出下载对话框请注释掉
- DefaultType application/x-httpd-php
- AddHandler x-httpd-php5 .php .html
- <IfModule mod_rewrite.c>
- RewriteEngine On
- #设置.htaccess的目录,根据服务器配置选择是否需要此行
- RewriteBase /
- RewriteCond %{HTTP_HOST} ^domain.com [NC]
- RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
- RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
- #将所有php,htm,html文件重写到missing.html
- RewriteRule ^(.*)\.php|\.htm|\.html(.*)$ missing.html$2
- </IfModule>
复制代码 根目录的missing.html文件内容- <?php
- function MYpath($path=null){ /*获取服务器绝对路径*/
- if (!empty($path)) {
- if (strpos($path,'\\')!==false) {
- return substr($path,0,strrpos($path,'\\')).'/';
- } elseif (strpos($path,'/')!==false) {
- return substr($path,0,strrpos($path,'/')).'/';
- }
- }
- return './';
- }
- function MYext($url){ /*获取文件扩展名*/
- $path=parse_url($url);
- $str=explode('.',$path['path']);
- return $str[1];
- }
- define('W_R_P',MYpath(__FILE__));
- $myurl = $_SERVER['REQUEST_URI']; /*完整url*/
- $path = pathinfo($myurl);
- /*获取实际文件名*/
- if($path['extension']=='html' && strpos($path['filename'],'-')){ /*如果启用了伪静态,根据实际情况修改*/
- $myfiles = explode('-',$path['filename']);
- $myfile = str_replace(array('//','\\'),array('/',''),$_SERVER['DOCUMENT_ROOT'].$path['dirname'].'/'.$myfiles[0].'.php');
- }else{ /*如果没有启用伪静态,根据实际情况修改*/
- $myfile = str_replace(array('//','\\'),array('/',''),$_SERVER['DOCUMENT_ROOT'].$path['dirname'].'/'.$path['filename'].'.'.MYext($myurl));
- if(strpos($myfile,'?')){
- $myfiles = explode('?',$myfile);
- $myfile = $myfiles[0];
- }
- }
- /*重新定义系统变量PHP_SELF*/
- $pathdirfile = pathinfo($_SERVER['REQUEST_URI']);
- if(strpos($pathdirfile['filename'],'.php')){$path3=explode('.php',$pathdirfile['filename']);$pathdirfile['filename']=$path3[0];}
- $php_self = $pathdirfile['filename'] ? str_replace(array('//','\\'),array('/',''),$pathdirfile['dirname'].'/'.$pathdirfile['filename'].'.php') : str_replace(array('//','\\'),array('/',''),$pathdirfile['dirname']);
- $_SERVER['PHP_SELF'] = $php_self;
- if(strpos($myurl,'adminjob')){ /*如果路径中包含adminjob则认为是管理后台*/
- require_once('admin.php');
- }elseif(substr($myfile,-1)=='.'){ /*如果文件名为小数点则认为没有文件名*/
- require_once('index.php');
- }elseif(file_exists($myfile)){ /*如果文件存在则正常执行*/
- require_once($myfile);
- }else{ /*如果文件不存在则调用首页,访问所有页面都显示首页则说明没有正常获取到文件名*/
- require_once('index.php');
- }
- ?>
复制代码 以上为本人对针对phpwind论坛程序所做的成功案例,另外对ecshop商店程序也使用成功,missing.html文件须要配合你的程序来使用
祝大家成功 |
|