我有一个的index.php它处理所有路由的index.php?网页=控制器(简体)刚分手的逻辑与观点。
选项+了FollowSymLinks RewriteEngine叙述上 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 重写规则^?([\ w \ D〜%:_ \ - ] +)$ index.php页面= $ 1 [NC]
这基本上是: HTTP://localhost/index.php页=控制器 为了
的http://本地主机/控制器/
谁能帮我在重写为
localhost/controller/param/value/param/value (和soforth)
这将是:
localhost/controller/?param=value¶m=value
我不能让它与重写规则的工作。
一个控制器可以是这样的:
< PHP 如果(使用isset($ _ GET ['行动'])){ 如果($ _ GET ['行动'] =='删除'){ do_Delete_stuff_here(); } } ?>和也:
< PHP 如果(使用isset($ _ GET ['动作'])及&安培;使用isset($ _ GET ['×'])){ 如果($ _ GET ['行动'] =='删除'){ do_Delete_stuff_here(); } } ?>解决方案
基本上,人们试图说的是,你可以像这样重写规则:
重写规则^(。*)$的index.php?PARAMS = $ 1 [NC]这会使你的实际php文件,如下所示:
的index.php?PARAMS =参数/值/参数/值和实际的URL将会像这样:
url/params/param/value/param/value
而在你的PHP文件,你可以通过这个爆炸像这样访问您的PARAMS:
< PHP $ PARAMS =爆炸(/,$ _ GET ['参数']); 为($ i = 0; $ I<计数($ params)方法; $ I + = 2){ 。回声$ PARAMS [$ i]有值。 $ PARAMS [$ I + 1]。< BR />中; } ?>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 ^([\w\d~%.:_\-]+)$ index.php?page=$1 [NC]Which basically: localhost/index.php?page=controller To
localhost/controller/
Can anyone help me add the Rewrite for
localhost/controller/param/value/param/value (And soforth)
That would be:
localhost/controller/?param=value¶m=value
I can't get it to work with the Rewriterule.
A controller could look like this:
<?php if (isset($_GET['action'])) { if ($_GET['action'] == 'delete') { do_Delete_stuff_here(); } } ?>And also:
<?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]This will make your actual php file like so:
index.php?params=param/value/param/valueAnd your actual URL would be like so:
url/params/param/value/param/valueAnd 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变量
发布评论