我在這裏被困在這裏,我正試圖弄清楚爲什麼它不工作!如何使用htaccess來做到這一點?
這是希望得到的URL看起來像
example.com/news/top/
從
example.com/index.php?view=news&task=top
,但我需要它這樣說, 「任務」 可以是一些不同勢像
example.com/index.php?view=news&task=newest
example.com/index.php?view=news&task=help
example.com/index.php?view=news&task=write
....
current .htaccess的樣子:
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/([^/\.]+) index.php?view=$1&task=$2
如果我訪問www.example.com/news/ - >它只是如果我訪問www.example.com/news/top/加載的index.php,但沒有通過視圖=新聞
? - >它工作得很好。
但我需要他們兩個的工作,加入了新的生產線爲.htaccess,如:
RewriteRule ^news/ index.php?view=news
然後參觀www.example.com/news/工作正常,但來訪的www.example.com/news/top /這將不可能獲得任務的價值。
請幫幫我!
預先感謝您。
重寫規則^新聞/頂/的index.php?任務=新聞和任務= $ 1 [L],但這不起作用 – rokkz
看來你去爲RESTful架構。閱讀MVC模式,你會得到一個路由這些請求的好主意。這可能有所幫助:http://www.lornajane.net/posts/2012/building-a-restful-php-server-understanding-the-request – CP510