阿泽阿泽

php和apache伪静态的一些常用代码

  1. htaccess中设置图片防盗链

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www.)?Aze.cn(/)?.$ [NC]
    RewriteRule .
    .(gif|jpg|jpeg|bmp|png)$ http://nothing_phpcn[R,NC,L]
    RewriteCond $1 !^(index.php|statics|upload|app.html|robots.txt)
    RewriteRule ^(.*)$ /index.php?/$1 [L]

  2. htaccess设置404 500错误页

    ErrorDocument 404 /statics/home/notfound.html
    ErrorDocument 500 /statics/home/notfound.html

  3. phpstudy伪静态错误No input file specified解决办法

apache No input filespecified,今天是我们配置apache RewriteRule时出现这种问题,解决办法很简单如下

打开.htaccess 在RewriteRule 后面的index.php教程后面添加一个“?”

完整代码如下

.htaccess

RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)  
RewriteRule ^(.*)$ /index.php?/$1 [L]
  1. Thinkphp非根目录无法加载模块

    .htaccess加RewriteBase /demo2/
    \demo2\ThinkPHP\Library\Think\Dispatcher.class.php 119行
    define('INFO',trim($_SERVER['PATH_INFO'],'/'));之前加:
    $_SERVER['PATH_INFO']=str_replace('/demo2','',$_SERVER['PATH_INFO']);

  2. CI框架伪静态iis-web.config配置参考

  3. thinkphp伪静态 去除index.php


    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

开启路由:

'URL_ROUTER_ON' => true, //URL路由
'URL_MODEL' => 2, // URL模式
  1. httpd.ini与.htaccess伪静态规则转换
    1486445829306171[1].png

  2. TP正则路由

config.php

<?php
$conf_array=array(
    /*加载额外配置文件*/
    'LOAD_EXT_CONFIG'   => 'db,htaccess',
    .....
);

htaccess.php

<?php
$rules=array(
    'URL_ROUTER_ON'   => true, //开启路由
    'URL_ROUTE_RULES' => array( //定义路由规则
        '/^verifycode\/(\w+)$/'=>'g=Index&c=Verifycode&a=index&type=:1',    //验证码
        '/^upload_image$/'=>'g=Index&c=Image&a=upload',    //教程图片上传按钮
        /*登录相关*/
        '/^login\/login$/'=>'g=Index&c=Login&a=login',    //登录
        '/^login\/reg$/'=>'g=Index&c=Login&a=reg',    //注册
        '/^login\/logout$/'=>'g=Index&c=Login&a=logout',    //登录
    ),
);
return $rules;

#伪静态和泛域名
#此文件禁止在行内注释

RewriteEngine on
#禁止对图片等文件重写:没有这一条,所有的404都会执行index.php脚本,耗费大量资源。
RewriteCond %{REQUEST_URI} !((.).jpg|.jpeg|.bmp|.gif|.png|.js|.css)$
#禁止对/public文件夹内重写,作用同上
RewriteCond %{REQUEST_URI} !(^/public/(.
))$
#如果是一个物理存在的目录,禁止重写
RewriteCond %{REQUEST_FILENAME} !-d
#如果是一个物理存在的文件,禁止重写
RewriteCond %{REQUEST_FILENAME} !-f
#上面2条不识别REQUEST_FILENAME时的替代写法
#RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
#RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
#php api模式,服务器能识别PATH_INFO
#RewriteRule ^(.)$ index.php/$1 [QSA,PT,L]
#php fastcgi模式 服务器不识别PATH_INFO
RewriteRule ^(.
)$ index.php [E=PATH_INFO:$1,QSA,PT,L]

本原创文章未经允许不得转载 | 当前页面:阿泽 » php和apache伪静态的一些常用代码

评论