重定向 URL(使用特定的 GET 参数) [英] Redirecting URLs (with specific GET parameters)

查看:34
本文介绍了重定向 URL(使用特定的 GET 参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个旧的调查链接已被另一个链接取代,所以基本上我希望任何人都试图访问该 URL:

I have this old survey link that is has been superseded by another link, so basically I want anyone trying to access the URL:

http://mywebsite.com/survey/view_survey.php?surveyID=1

重定向到:

http://mywebsite.com/survey/view_survey.php?surveyID=2

我可以在 Apache 配置或 htaccess 文件中执行此操作吗?

Can I do this in the Apache configuration or htaccess file?

我在 httpd.conf 文件的重定向部分尝试了以下规则:

I tried the following rule in the Redirect section of my httpd.conf file:

Redirect 301 /survey/view_survey.php?surveyID=1 http://mywebsite.com/survey/view_survey.php?surveyID=2

但它不起作用.我怀疑处理规则时没有使用 GET 参数.

But it doesn't work. I am suspecting that the GET parameters are not used when processing the rule.

破解代码以重定向特定调查 ID 是我唯一的选择吗?

Is my only option to hack my code to redirect on a specific surveyID?

按照使用重写规则的建议,我在我的 .htaccess 文件中尝试了以下内容:

Following the suggestion of using the Rewrite rules, I tried the following in my .htaccess file:

RewriteRule ^survey/view_survey\.php\?surveyID=1525$ /survey/view_survey.php?sur
veyID=1607

但这行不通.我确实启动并运行了重写引擎,因为我当前正在运行另一个重写规则.

But that doesn't work. I do have the rewrite engine up and running, because I have another rewrite rule currently running.

推荐答案

在 .htaccess 文件中试试这个:

Try this in a .htaccess file:

RewriteEngine on
RewriteCond %{QUERY_STRING} (^|.*&)surveyID=1525(&.*|$)
RewriteRule ^survey/view_survey\.php$ /survey/view_survey.php?%1surveyID=1607%2 [L,R=301]

这篇关于重定向 URL(使用特定的 GET 参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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