重写和URL解码 [英] rewrite and url decoding

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

问题描述

似乎某个网站链接到我的网站的方式不好. 从Google网站管理员工具中,我看到了404错误

It seems a site is linking to mine in a bad way. From google webmaster tools I see some 404 errors

domain.com/file.php?id=1 (404) Not found    (Date)

此网址可以正常使用,但由于浏览器页面解码,真正的(404)网址为

This url works ok but because of browser page decoding, the real (404) url is

domain.com/file.php%3Fid%3D1 (this is what my browser displays in the url input when I click on google url)

我的第一次尝试是

RewriteRule ^(.*)\%3F(.*)$ $1?$2 [R=301, L]

%3F更改为'?',但是它不起作用.令人困惑的是真实的东西和已编码/解码的东西.

to change %3F to '?' but it does not work. It is confusing what is real and what is en/decoded.

谢谢

推荐答案

这不是一个优雅的解决方案,但是几个月后,这是我找到的唯一方法.

It is not an elegant solution, but after months, it is the only way I found.

常规情况

domain.tld/dir/file.php?id=UID&qty=NUM&...   (from old site structure)

被重写为

domain.tld/newfile.php?id=UID&qty=NUM&... [R=301,L]

因此,对于类似

domain.tld/dir/file.php%3Fid%3DUID%26qty=NUM%26...   (from old site structure)

我表演

RewriteRule ^dir/file\.php(.*)$ script.php?qs=$1 [R,L]

这必须在涉及dir/file.php的所有指令之后

This MUST be AFTER all directives that involves dir/file.php

然后我可以在script.php中处理查询字符串$ _GET ['qs']

Then I can handle the query string $_GET['qs'] in script.php

这可能不适用于其他可能进入循环或出现不良结果的情况.

It may not apply to other situations that would enter into a loop or undesired results.

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

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