php和apache偽靜態的一些常用程式碼

PHP中文网
發布: 2023-03-05 14:26:01
原創
2065 人瀏覽過

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配置参考



    
        
            
            
                    
                
                
                    
                    
                
                      
                    
                    
                
            
        
    
登入後複製

6. 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模式

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

php和apache偽靜態的一些常用程式碼

8. TP正则路由

config.php

 'db,htaccess',
    .....
);
登入後複製


htaccess.php

 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.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!