0

我想将带有查询字符串的 URL 重定向到另一个也有查询字符串的 URL。

我将如何将 URL 重定向/opinion/feature.php?id=97/article/article.php?id=1494

4

2 回答 2

0
# Turn ON RewriteEngine 
RewriteEngine on

RewriteRule ^/opinion/feature.php(.*)$ http://www.yourdomain.com/article/article.php$1 [NE,L,R=301]

用户评论后编辑: 如果您只有 1 个要重定向的 URL,并使用您提到的修复 ID 值,您可以在下面使用:

# Turn ON RewriteEngine 
RewriteEngine on

RewriteRule ^/opinion/feature.php\?id=97$ http://www.yourdomain.com/article/article.php\?id=1494 [NE,L,R=301]

如果你有多个相似的URL(相对较少的数字并且你知道两个对应的ID)你可以在这里类似地放置,否则最好通过header()函数处理基于两个id映射的PHP重定向

于 2013-06-12T05:12:43.900 回答
0

一般来说,您不需要指定任何内容来附加查询字符串。

以下应该工作

Keep original query (default behavior)
RewriteRule ^page\.php$ /target.php [L]
# from http://example.com/page.php?foo=bar
# to   http://example.com/target.php?foo=bar
于 2013-06-12T05:12:15.567 回答