php和apache偽靜態一些常用代碼

來源:互聯網
上載者:User
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

<?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;
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.