• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-22) 13次浏览 已收录 0个评论

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.htmlErrorDocument 500 /statics/home/notfound.html

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

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

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

完整代码如下

.htaccessRewriteEngine onRewriteCond $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 onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>

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

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

8. TP正则路由

config.php

&l<p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite>t;?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;

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php和apache伪静态的一些常用代码

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址