使用 htaccess 获取 URL 中的两个变量

发布于 2024-08-27 17:44:13 字数 929 浏览 4 评论 0原文

通过htaccess获取URL中的两个GET方法是怎样的?

RewriteRule ^adm/(.*)$ adm.php?mode=$1

我已经将其用于示例 URL:

http://www.domain.com/adm/thismode

现在我想获得两种方法,例如:

http://www.domain.com/adm/thismode/othermode

我已经尝试过这个:

RewriteRule ^adm/(.*)$/(.*)$ adm.php?mode=$1&othermode=$2

但似乎不起作用...我该如何让它做到这一点?

编辑:

$mode1 = $_GET['mode'];

$mode2 = $_GET['othermode'];

像这样...

再次编辑:

http://www.domain.com/adm/generated/pass/6z9c4q9k8p

对...这是它必须做的URL

在PHP中它有这样的:

if($mode == "generated")

我希望PHP查看URL中是否设置了模式并且生成的密码是另一个 GET

我将 htaccess 如下:

RewriteRule ^adm/(.*)/(.*)$ adm.php?mode=$1&generated=$2

PHP 还将抓取 URL 中生成的密码并将其显示在页面上。

What way it is to be to get two GET methods in the URL by htaccess?

RewriteRule ^adm/(.*)$ adm.php?mode=$1

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

I've tried this:

RewriteRule ^adm/(.*)$/(.*)$ adm.php?mode=$1&othermode=$2

But doesn't seem to work... how do I get it to do that?

EDIT:

$mode1 = $_GET['mode'];

$mode2 = $_GET['othermode'];

Like this...

EDIT AGAIN:

http://www.domain.com/adm/generated/pass/6z9c4q9k8p

Right... this is the URL it has to do

And in the PHP it has this:

if($mode == "generated")

I want the PHP to see if the mode is set in the URL and the generated password is the other GET

I put the htaccess as this way:

RewriteRule ^adm/(.*)/(.*)$ adm.php?mode=$1&generated=$2

The PHP will also grab the generated password in the URL and display it on the page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我偏爱纯白色 2024-09-03 17:44:13

您现在遇到的问题是什么 看来理查德已经为您提供了您需要的东西?

使用您的示例 URL:

http://www.domain.com/adm/generated/pass/6z9c4q9k8p

以及 .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;

或者这不是您的问题?

what's the problem you're having now Seems like Richard got you what you needed?

Using your example URL:

http://www.domain.com/adm/generated/pass/6z9c4q9k8p

and the following in your .htaccess

RewriteRule ^adm/(.*)/(.*)/(.*)$ adm.php?mode=$1&generated=$2&pass=$3

then you can do:

$mode1 = $_GET['mode'];
$generated = $_GET['generated'];
$pass = $_GET['pass'];
if ( $mode1 == 'generated' && $generated == 'pass' ) 
    echo $pass;

or was that not your question?

被你宠の有点坏 2024-09-03 17:44:13

在 Perl 兼容的正则表达式中,$ 是一个锚点,表示“结束”。因此,请从模式中间的 ^adm/(.*) 之后删除 $

RewriteRule ^adm/(.*)/(.*)$ adm.php?mode=$1&othermode=$2

In Perl compatible RegExs a $ is an anchor, which denotes "the end". So remove the $ from the middle of your pattern, after ^adm/(.*):

RewriteRule ^adm/(.*)/(.*)$ adm.php?mode=$1&othermode=$2
阳光下的泡沫是彩色的 2024-09-03 17:44:13

我不会在 .htaccess 中编写复杂的正则表达式,而是使用一个简单的正则表达式

RewriteCond $1 !^adm\.php
RewriteRule ^adm/(.*)$ adm.php/$1 [L]

,并在 adm.php 中使用 $_SERVER['PHP_SELF'] ,这样您就可以处理任何一种以 adm 开头且不更改 .htaccess 的复杂 URL。

Instead of writing complex regular expressions in the .htaccess, I would just use a simple

RewriteCond $1 !^adm\.php
RewriteRule ^adm/(.*)$ adm.php/$1 [L]

and work with $_SERVER['PHP_SELF'] inside adm.php so you can handle any kind of complex URL which starts with adm without changing the .htaccess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文