的.htaccess重写GET变量

编程入门 行业动态 更新时间:2024-10-15 06:16:25
本文介绍了的.htaccess重写GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个的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&param=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&param=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/value

And your actual URL would be like so:

url/params/param/value/param/value

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变量

本文发布于:2023-10-11 14:14:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   变量   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!