Apache 重新導向~ Redirect(Rewrite)實作@@

好久沒寫網頁說XD

因為某些原因我給熬想說用這方式~~~這樣我就不用~~同內容但不同檔名的檔案一直複製

好險apache有這功能@@~~~~~~很像cakePHP的運作原理~~~~~~~

但要用之前要把這個打開 ~~~~(前面的#拿掉)

LoadModule rewrite_module modules/mod_rewrite.so

然後,htaccess檔案~~~~~寫成這樣

<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*)php$ index.php [L]
</ifmodule>

測試結果~~~管他我打甚麼網誌~~~bitty.php或是ferrari.php都會連到同個檔案index.php

但只限於php結尾= =

一開始我打這樣~~~~~~結果會變成css/main.css這個檔案也被導向到index.php
RewriteRule (.*) index.php [L]

所以後來改成以php結尾~~~~~就正常了

參考資料~~張睪提供的
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Regular Expression的用法~~我也是上去看才知道$結尾用法= =
http://phi.sinica.edu.tw/aspac/reports/94/94019/ch2.html

沒有留言: