重写查询字符串 [英] Rewrite Query String

查看:37
本文介绍了重写查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网址:

oldsite.com/profile.php?uid=10

我想改写为:

newsite.com/utenti/10

我该怎么做?

更新:我是这样写的:

RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$RewriteRule ^profile\.php$ http://www.newsite.com/utenti/$1 [R=301,L]

但是 $1 匹配完整的查询字符串,而不仅仅是用户 ID.

解决方案

要在重写条件中使用匹配项,您必须使用 %1 而不是 $1.此外,如果您想删除查询字符串的其余部分,您必须附加一个 ?

<前>RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$重写规则 ^profile\.php$ http://www.newsite.com/utenti/%1?[R=301,L]

I have this URL:

oldsite.com/profile.php?uid=10

I would like to rewrite it to:

newsite.com/utenti/10

How can I do that?

UPDATE: I wrote this:

RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$
RewriteRule ^profile\.php$ http://www.newsite.com/utenti/$1 [R=301,L]

But $1 match the full query string and not just the user id.

解决方案

To use matches in the rewrite conditions, you have to use %1 instead of $1. Also, if you wish to remove the rest of the query string you have to append a ?

RewriteCond %{QUERY_STRING} ^uid=([0-9]+)$
RewriteRule ^profile\.php$ http://www.newsite.com/utenti/%1? [R=301,L]

这篇关于重写查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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