登录  /  注册
php和apache伪静态的一些常用代码
PHP中文网
发布: 2023-03-05 14:26:01
原创
1564人浏览过

1. htaccess中设置图片防盗链

RewriteEngine on
##################################################
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?php.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]
登录后复制

4. 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']);
登录后复制

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

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules><remove name=""/>
            <rule name="规则 0" stopProcessing="true">
                    <match url="^(statics|upload|robots\.txt)" />
                </rule>
                <rule name="规则 1" stopProcessing="true">
                    <match url="^((?!admin).*)$" />
                    <action type="Rewrite" url="index.php?/{R:1}" />
                </rule>
                      <rule name="规则 2" stopProcessing="true">
                    <match url="^admin(/?)([!/].*)?$" />
                    <action type="Rewrite" url="admin.php?{R:1}{R:2}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
登录后复制

6. thinkphp伪静态 去除index.php

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
登录后复制

开启路由:
'URL_ROUTER_ON' => true, //URL路由
'URL_MODEL' => 2, // URL模式

7. httpd.ini与.htaccess伪静态规则转换

httpd.ini与.htaccess伪静态规则转换.png

8. 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;
登录后复制


来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学