基于在.htaccess中GET变量的301重定向的URL [英] 301 Redirecting URLs based on GET variables in .htaccess

查看:233
本文介绍了基于在.htaccess中GET变量的301重定向的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢...

http://www.example.com/bunch。中/不需要/废话的OpenDocument和放大器;部分= 1

http://www.example.com/bunch。中/不需要/废话的OpenDocument和放大器;部分= 2

......,我想重定向到新的,更清洁的形式...

...that I want to redirect to the newer, cleaner form...

http://www.example.com/page.php/welcome

http://www.example.com/page.php/prices

我明白我也可以把一个网页到另一个用一个简单的重定向,即

I understand I can redirect one page to another with a simple redirect i.e.

重定向301 /bunch.of/unneeded/crap http://www.example.com/page。 PHP

Redirect 301 /bunch.of/unneeded/crap http://www.example.com/page.php

不过该人士页面没有改变,只是它的GET增值经销​​商。我无法弄清楚如何立足重定向这些GET变量的值。任何人都可以帮助请!?我相当方便的与旧的正则表达式,所以我可以有一个流行的使用mod-rewrite,如果我有,但我不明确语法的重写GET VAR和我preFER,以避免性能下降和使用清洁器重定向指令。有什么办法?如果不是任何人都可以给我介绍,以正确的mod-rewrite语法PLS?

But the source page doesn't change, only it's GET vars. I can't figure out how to base the redirect on the value of these GET variables. Can anybody help pls!? I'm fairly handy with the old regexes so I can have a pop at using mod-rewrite if I have to but I'm not clear on the syntax for rewriting GET vars and I'd prefer to avoid the performance hit and use the cleaner Redirect directive. Is there a way? and if not can anyone clue me in as to the right mod-rewrite syntax pls?

干杯,

罗杰。

推荐答案

由于在URL查询参数可以是任意的顺序,你需要使用任何一个的 的RewriteCond 指令的每一个参数检查或为每个可能的permutiation。

As the parameters in the URL query may have an arbitrary order, you need to use a either one RewriteCond directive for every parameter to check or for every possible permutiation.

下面是一个的RewriteCond 指令,每个参数的一个例子:

Here’s an example with a RewriteCond directive for each parameter:

RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=1(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/welcome? [L,R=301]

RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=2(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/prices? [L,R=301]

但是,正如你所看到的,这可能会一塌糊涂。

But as you can see, this may get a mess.

因此​​,一个更好的办法可能是使用一个 RewriteMap指令 。最简单的是用纯文本文件的的对:

So a better approach might be to use a RewriteMap. The easiest would be a plain text file with key and value pairs:

1 welcome
2 prices

要定义地图,写在你的服务器或virual主机配置(该指令是不是在每个目录范围内允许)以下指令:

To define your map, write the following directive in your server or virual host configuration (this directive is not allowed in per-directory context):

RewriteMap examplemap txt:/path/to/file/map.txt

然后,你就只需要一个规则:

Then you would just need one rule:

RewriteCond %{QUERY_STRING} ^([^&]&)*opendocument(&|$)
RewriteCond %{QUERY_STRING} ^([^&]&)*part=([0-9]+)(&|$)
RewriteRule ^bunch\.of/unneeded/crap$ /page.php/%{examplemap:%2}? [L,R=301]

这篇关于基于在.htaccess中GET变量的301重定向的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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