我有一个 index.php 来处理所有的路由 index.php?page=controller (simplified) 只是为了将逻辑与视图分开.
I have a index.php which handle all the routing index.php?page=controller (simplified) just to split up the logic with the view.
Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([wd~%.:_-]+)$ index.php?page=$1 [NC]基本上:localhost/index.php?page=controller到
localhost/controller/
谁能帮我添加重写
localhost/controller/param/value/param/value (以此类推)
那就是:
localhost/controller/?param=value¶m=value
我无法让它与 Rewriterule 一起使用.
I can't get it to work with the Rewriterule.
控制器可能如下所示:
<?php if (isset($_GET['action'])) { if ($_GET['action'] == 'delete') { do_Delete_stuff_here(); } } ?>还有:
<?php if (isset($_GET['action']) && isset($_GET['x'])) { if ($_GET['action'] == 'delete') { do_Delete_stuff_here(); } } ?> 推荐答案基本上人们想说的是,你可以像这样制定重写规则:
Basically what people try to say is, you can make a rewrite rule like so:
RewriteRule ^(.*)$ index.php?params=$1 [NC, QSA]这将使您的实际 php 文件像这样:
This will make your actual php file like so:
index.php?params=param/value/param/value您的实际 URL 如下所示:
And your actual URL would be like so:
url/params/param/value/param/value在你的 PHP 文件中,你可以通过像这样分解来访问你的参数:
And in your PHP file you could access your params by exploding this like so:
<?php $params = explode( "/", $_GET['params'] ); for($i = 0; $i < count($params); $i+=2) { echo $params[$i] ." has value: ". $params[$i+1] ."<br />"; } ?>更多推荐
.htaccess 重写 GET 变量
发布评论