的.htaccess重写GET变量 [英] .htaccess rewrite GET variables

查看:313
本文介绍了的.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://本地主机/控制器/

谁能帮我在重写为

<一个href="http://localhost/controller/param/value/param/value">http://localhost/controller/param/value/param/value (和soforth)

这将是:

<一个href="http://localhost/controller/?param=value&param=value">http://localhost/controller/?param=value&param=value

我不能让它与重写规则的工作。

一个控制器可以是这样的:

 &LT; PHP
如果(使用isset($ _ GET ['行动'])){
 如果($ _ GET ['行动'] =='删除'){
do_Delete_stuff_here();
}
}
?&GT;
 

和也:

 &LT; PHP
如果(使用isset($ _ GET ['动作'])及&安培;使用isset($ _ GET ['×'])){
 如果($ _ GET ['行动'] =='删除'){
do_Delete_stuff_here();
}
}
?&GT;
 

解决方案

基本上,人们试图说的是,你可以像这样重写规则:

 重写规则^(。*)$的index.php?PARAMS = $ 1 [NC]
 

这会使你的实际php文件,如下所示:

 的index.php?PARAMS =参数/值/参数/值
 

和实际的URL将会像这样:

  http://url.com/params/param/value/param/value
 

而在你的PHP文件,你可以通过这个爆炸像​​这样访问您的PARAMS:

 &LT; PHP

$ PARAMS =爆炸(/,$ _ GET ['参数']);
为($ i = 0; $ I&LT;计数($ params)方法; $ I + = 2){

  。回声$ PARAMS [$ i]有值。 $ PARAMS [$ I + 1]。&LT; BR /&gt;中;

}

?&GT;
 

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: http://localhost/index.php?page=controller To

http://localhost/controller/

Can anyone help me add the Rewrite for

http://localhost/controller/param/value/param/value (And soforth)

That would be:

http://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:

http://url.com/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变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆