.htaccess使用GET参数重定向 [英] .htaccess redirect using GET parameters

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

问题描述

我已经检查了很多与.htaccess重定向有关的答案,但是我无法阐明我的问题:

I have already checked a lot of answers related to .htaccess redirecting, but yet I was unable to elaborate my problem:

我有一个旧网站,博客条目的地址是这样的:

I have an old website with blog entries addressed like this:

http://ellrohir.mzf.cz/index .php?page = blog& id = 77

http://ellrohir.mzf.cz/index.php?page=blog&id=77

现在,我还有一个新网站,其中包含漂亮的网址",您可以使用以下网址找到博客条目:

Now I also have a new website with "nice urls" where blog entries can be found using:

http://alois-seckar.cz/politics-blog/77

http://alois-seckar.cz/politics-blog/77

我想关闭"旧页面,并将所有旧链接重定向到新站点.如何捕获旧的URL并将其转移到新的URL?我仍然无法弄清楚必要的.htaccess代码:(

I want to "shut down" the old page and redirect any old links to new site. How to catch and transfer the old url to the new url? I still cannot figure the necessary .htaccess code up :(

推荐答案

尝试一下:

RewriteEngine on


RewriteCond %{QUERY_STRING} ^page=([^&]+)&id=([^&]+)$ [NC]
RewriteRule ^index\.php$ http://alois-seckar.cz/politics-%1/%2? [NC,L,R]

结尾的空问号对于丢弃目标网址中的原始查询字符串很重要.

Empty question mark at the end is important to discard the orignal query strings from the destination url.

%n是RewriteCond中正则表达式的一部分,它是([和] +)之间匹配的部分.

%n is part of the regex in RewriteCond, it's the part matched between ([ and ]+).

此规则将重定向

example.com/index.php?page=foo&id=bar

example2.com/politics-foo/bar

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

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