PHP 및 Apache 의사 정적에 대한 몇 가지 일반적인 코드

PHP中文网
풀어 주다: 2023-03-05 14:26:01
원래의
2190명이 탐색했습니다.

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伪静态规则转换

PHP 및 Apache 의사 정적에 대한 몇 가지 일반적인 코드

8. TP正则路由

config.php

<?php
$conf_array=array(
    /*加载额外配置文件*/
    &#39;LOAD_EXT_CONFIG&#39;   => &#39;db,htaccess&#39;,
    .....
);
로그인 후 복사


htaccess.php

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


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!