ThinkPHP3 偽靜態和URL重寫 多重匹配的簡單設定
根據ThinkPHP3.0的手冊URL重寫的那一節配置Apache。
然後再網站根目錄下放置.htaccess檔案,內容如手冊所提示的一樣
win2003的空間iis6不支援.htaccess,儘可能選用linux系統的伺服器
?
RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]轉載請註明出處:http://tyllxx.iteye.com?
?
雖然可以用URL_HTML_SUFFIX實現偽靜態,但是這裡的方法是使用.htaccess檔案來實現。
以上代碼可以實現讓:
http://serverName/index.php/Blog/read/id/1
變為:
http://serverName/Blog/read/id/1
?
那麼還要讓其變為:
http://serverName/Blog/1.html
?
若還有:
http://serverName/buy/1.html
http://serverName/topic/diy.html
怎麼實現呢?
?
以下是實現方法:(.html尾碼,自己在寫串連時自己加上,用URL_HTML_SUFFIX方式,去掉方法中的.html)
?
?
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT] RewriteRule ^(.*)/topic/(.*)\.html$ $1/topic/Index/index/links/$2 [QSA,PT] RewriteRule ^(.*)/buy/(.*)\.html$ $1/buy/Index/index/id/$2 [QSA,PT,L]轉載請註明出處:http://tyllxx.iteye.com?
此方法已經驗證過,只需要修改匹配欄位和替換欄位即可使用。