使用 htaccess 在 URL 中获取两个变量 [英] Getting two variables in the URL with htaccess
问题描述
htaccess 获取 URL 中的两个 GET 方法是什么方式?
What way it is to be to get two GET methods in the URL by htaccess?
RewriteRule ^adm/(.*)$ adm.php?mode=$1
我已将其用于示例 URL:
I've used that for the example URL:
http://www.domain.com/adm/thismode
现在我想获得两种方法,例如:
Now I want to get two methods like:
http://www.domain.com/adm/thismode/othermode
我已经试过了:
RewriteRule ^adm/(.*)$/(.*)$ adm.php?mode=$1&othermode=$2
但似乎不起作用……我如何让它做到这一点?
But doesn't seem to work... how do I get it to do that?
$mode1 = $_GET['mode'];
$mode1 = $_GET['mode'];
$mode2 = $_GET['othermode'];
$mode2 = $_GET['othermode'];
像这样...
再次
http://www.domain.com/adm/generated/pass/6z9c4q9k8p
对...这是它必须做的网址
Right... this is the URL it has to do
在 PHP 中有这样的:
And in the PHP it has this:
if($mode == "generated")
我想让PHP看看是不是在URL中设置了模式,生成的密码是另一个GET
I want the PHP to see if the mode is set in the URL and the generated password is the other GET
我把 htaccess 设为这样:
I put the htaccess as this way:
RewriteRule ^adm/(.*)/(.*)$ adm.php?mode=$1&generated=$2
PHP 也会抓取 URL 中生成的密码并将其显示在页面上.
The PHP will also grab the generated password in the URL and display it on the page.
推荐答案
您现在遇到了什么问题 似乎 Richard 得到了您需要的东西?
what's the problem you're having now Seems like Richard got you what you needed?
使用您的示例网址:
http://www.domain.com/adm/generated/pass/6z9c4q9k8p
以及 .htaccess 中的以下内容
and the following in your .htaccess
RewriteRule ^adm/(.*)/(.*)/(.*)$ adm.php?mode=$1&generated=$2&pass=$3
那么你可以这样做:
$mode1 = $_GET['mode'];
$generated = $_GET['generated'];
$pass = $_GET['pass'];
if ( $mode1 == 'generated' && $generated == 'pass' )
echo $pass;
或者这不是你的问题?
这篇关于使用 htaccess 在 URL 中获取两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!