当不遵守规则时,Mod 重写并使用 PHP 的 GET 获取 URL

Mod Rewrite and Using PHP#39;s GET for URL#39;s When not Following the Rules(当不遵守规则时,Mod 重写并使用 PHP 的 GET 获取 URL)
本文介绍了当不遵守规则时,Mod 重写并使用 PHP 的 GET 获取 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想不出一个好的标题,这很难解释.基本上,我的服务器上有 mod_rewrite 设置.它将每个 ?a=1&b=2&c=3 etc 变成/1/2/3/

I couldn't think of a good title for this, it's hard to explain. Basically, I have mod_rewrite setup on my server. It turns each ?a=1&b=2&c=3 etc into /1/2/3/

我想实现一个功能,我可以这样做:/login/?return_url=/home/return_url 将根据用户上次所在的位置而变化.我知道还有其他方法可以找出返回 url,但我想将其保留在 URL 中.

I want to implement a feature where I can do something like this: /login/?return_url=/home/ The return_url would change depending on where the user was last. I know there are other methods of finding out the return url, but I would like to keep it in the URL.

我的问题是以下内容不起作用:/login/?return_url=/home/

My issue is that the following does not work: /login/?return_url=/home/

但是,/login.php?return_url=/home/ 确实有效.

为什么 PHP 在第一种(首选)情况下看不到 return_url 变量?

Why can't PHP see the return_url variable in the first (preferred) situation?

这是我当前的代码:

RewriteRule ^(.*)/(.*)/(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2&c=$3&d=$4 [L]
RewriteRule ^(.*)/(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2&c=$3 [L]
RewriteRule ^(.*)/([A-Za-z0-9_-]+)/$ /?a=$1&b=$2 [L]
RewriteRule ^([A-Za-z0-9_-]+)/$ /?a=$1 [L]

推荐答案

QSA 指令 可能就是你要找的:

The QSA directive is probably what you're looking for:

'qsappend|QSA'(查询字符串追加)
此标志强制重写引擎将替换字符串的查询字符串部分附加到现有的字符串,而不是替换它.当你想要的时候使用这个通过重写规则向查询字符串添加更多数据.

'qsappend|QSA' (query string append)
This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

例如,

RewriteRule ^something/([0-9]+)$ something.php?id=$1 [QSA]

会让 something/9?key=val 转到 something.php?id=9&key=val

这篇关于当不遵守规则时,Mod 重写并使用 PHP 的 GET 获取 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)