謝謝大家的耐心和幫助。我完全重申了這個問題,因爲我的所有修改都會變得很長。 我有4個的入口點的PHP MVC框架:URL重寫幫助
從根:
的index.php
索引ajax.php
管理員/ index.php的
管理員/索引-ajax.php
我需要一個.htcaccess文件,它可以接受任何請求,並根據url將其重寫到相應的文件中。長的網址是index.php?rt = cms/view/15,我希望它是index/cms/view/15。除了一個問題外,這一部分已經完成了。
這是我現在的.htaccess文件:
# htaccess file for framework - GOOD
Options +FollowSymLinks
# Turn on the mod_rewrite engine - GOOD
RewriteEngine On
# Hide indexes - GOOD
Options -Indexes
# If a file is not one of these, continue processing. - GOOD
RewriteRule \.(css|js|jpg|jpeg|png|gif|ico)$ - [L]
# RewriteRules for folder index files
#RewriteRule ^(index)?(.php)?$ index.php [L] - GOOD
#RewriteRule ^admin(/?)(index)?(.php)?$ admin/index.php [L] - GOOD
# RewriteRules for admin folder arguements - going from more specific to less
RewriteRule ^admin/ajax/[A-Za-z0-9-_/]*$ admin/index-ajax.php?rt=$1 [L]
RewriteRule ^admin/[A-Za-z0-9-_/]*$ admin/index.php?rt=$1 [L]
# RewriteRule for root ajax file
RewriteRule ^ajax/[A-Za-z0-9-_/]*$ index-ajax.php?rt=$1 [L]
# RewriteRule for root file - by here, it is not ajax or admin related, so only
# possible option left if the root index file
RewriteRule ^[A-Za-z0-9-_/]*$ index.php?rt=$1 [L]
我做了一個簡單的網站有兩個文件夾 - 「根」和「根/管理員」,而且每個的內部的CSS,圖片,和一些虛擬內容的JavaScript文件夾。在'root'和'root/admin'裏面有一個index.php和index-ajax.php文件,可以簡單地輸出任何url參數,並且使用來自每個文件夾的css,js和image文件。
我現在的問題是,如果我做一個像索引/等等或/管理/索引/等等的網址,那麼該網頁提出正確的參數是正確的。然而,當我做了像索引/等/視圖或管理/索引/等/視圖的網址然後爭論是正確的(?rt = blah /視圖),但頁面呈現錯誤,因爲css/js/images文件去索引/ blah/[css]而不是索引/ [css]。
有關如何處理此問題的任何想法?我允許css/js/image文件通過.htaccess原樣通過,因此在那裏的工作量會減少。
我只是不明顯鍵入速度不夠明顯。 – seth 2009-07-08 21:50:22
我認爲$符號可作爲佔位符將來自左側網址的值轉移到正確的網址中? – 2009-07-08 21:52:34
他意味着第一部分中的$,/ – seth 2009-07-08 21:53:36