ThinkPHP3 偽靜態跟URL重寫 多重匹配的簡單設定

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

此方法已經驗證過,只需要修改匹配欄位和替換欄位即可使用。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.