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;