我如何在友好的URL使用GET方法。 [英] How do I use get method in friendly url.

查看:84
本文介绍了我如何在友好的URL使用GET方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网址是: http://rang.comli.com/servicecnt/service_id/5 。 使用.htaccess文件,我已经建立了友好url.I要使用$ _GET method.So到目前为止,我在PHP这样做来获取URL值,但我想知道如何使用$ _ GET方法获取和分配变量。

 < PHP
    $ HTP = $ _ SERVER ['REQUEST_URI'];
    $ htp_arr =爆炸(/,$ HTP);
    回声$ HTP;
    回声< pre>中;
    的print_r($ htp_arr)< BR />中。
    回声ID =$ htp_arr [3]&所述峰; br />中。;
    回声NAME =$ htp_arr [2]< BR />中。;
    回声名称2 =$ htp_arr [1]。&所述峰; br />中;
?>
 

解决方案

如果你使用的.htaccess的 -htaccess文件>然后只需使用:

  $服务ID = $ _GET ['service_id为'];
 

有关形式予以URI添加此规则:

 重写规则^形式予以/ tution_id /(\ d +)/ $ tution.php?tution_id == $ 1 [QSA,L]
 

my url is:http://rang.comli.com/servicecnt/service_id/5. Using .htaccess file,I have created the friendly url.I want to retrieve the url values by using $_GET method.So far I have done in php like this,but I want to know how to get by using $_GET method and assign to variable.

<?php
    $htp=$_SERVER['REQUEST_URI'];
    $htp_arr=explode("/",$htp);
    echo $htp;
    echo "<pre>";
    print_r($htp_arr)."<br/>";
    echo "ID=".$htp_arr[3]."<br/>";
    echo "Name=".$htp_arr[2]."<br/>";
    echo "Name2=".$htp_arr[1]."<br/>";
?>

解决方案

If you're using .htaccess from this answer then just use:

$serviceId = $_GET['service_id'];

For tution URI add this rule:

RewriteRule ^tution/tution_id/(\d+)/?$ tution.php?tution_id==$1 [QSA,L]

这篇关于我如何在友好的URL使用GET方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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