【发布时间】:2013-09-19 07:27:53
【问题描述】:
我目前正在做一个项目,我必须在 url 中传递三个参数。我的网址看起来像 -
localhost/newproject/index.php?file_name=clients&mode=edit&id=1
下面列出了我在传递不同参数时执行的功能
1) url - localhost/newproject/index.php?file_name=clients
功能 - 包含文件templates/modules/clients/clients.php
2) url - localhost/newproject/index.php?file_name=clients&mode=edit
功能 - 包含文件 template/modules/clients/cliemts-edit.php。由于未设置客户端 ID,因此客户端编辑屏幕将用于添加新客户端。
3) url - localhost/newproject/index.php?file_name=clients&mode=edit&id=1
功能 - 包含文件 template/modules/clients/cliemts-edit.php。并且客户端编辑屏幕将用于更新其 client_id 为 1 的客户端。现在,我正在尝试将此 url 转换为此
localhost/newproject/clients/edit/1
我的 htaccess 中有以下代码
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?file_name=$1&mode=$2&id=$3 [L]
RewriteRule ^([^/\.]+)$ index.php?file_name=$1 [L]
我面临的问题是,每当包含客户端编辑屏幕时,css 文件、javascript 文件和图像的路径都会更改。我该如何克服呢?
【问题讨论】:
-
如果你只是使用常规的 HTTP 参数,为什么还要重写 URL?
-
@NDM - 它使 URL 看起来更有条理。
标签: php .htaccess mod-rewrite