【发布时间】:2013-10-14 15:48:48
【问题描述】:
我在这里卡住了,我正在努力弄清楚为什么它不起作用!
这是想让网址看起来像
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
....
当前的 .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/ -> 它只加载 index.php 但不通过 ?view=news
如果我访问 www.example.com/news/top/ -> 效果很好。
但我需要它们都工作,向 .htaccess 添加一个新行,例如:
RewriteRule ^news/ index.php?view=news
然后访问 www.example.com/news/ 工作正常,但访问 www.example.com/news/top/ 将无法获得任务的价值。
请帮帮我!
提前谢谢你。
【问题讨论】:
-
RewriteRule ^news/top/index.php?task=news&task=$1 [L] 但这不起作用
-
看来您正在选择 RESTful 架构。阅读 MVC 模式,您将对路由这些请求有一个很好的了解。这可能会有所帮助:lornajane.net/posts/2012/…