重定向包含“?”的 URL文件名中的字符
我是一名 php/mysql 开发新手,需要一些帮助。
我正在与 .NET 开发人员一起开发一个项目。他在 .NET 中构建了一个 URL 重定向功能,该功能在 URL 中使用 ?
(例如,mysite.com?123
重定向到 www.realsite.com
我需要将我的域移至新服务器并在 php/mySQL 中重新创建此功能,我需要使用该功能来支持。这种技术(它们嵌入在 QR 代码中)我不需要以这种方式生成新重定向的解决方案 -
的新服务器将在 bluehost 上。
我 帮我。
I'm a novice php/mysql developer and need some help.
I was working on a project with a .NET developer. He built a URL redirecting function in .NET that uses the ?
in the URL (eg, mysite.com?123
redirects to www.realsite.com
. This developer has now disappeared on me and I no longer have access to the server.
I need to move my domain to a new server and recreate this functionality in php/mySQL. I have about 40 urls that I need to support using this technique (they're embedded in QR codes). I don't need a solution that generates new redirects this way - I've got a different solution going forward.
My new server will be on bluehost.
Many thanks to anyone who can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要复制原始设置,您根本不需要涉及 PHP。您可以使用一些
RewriteRules
在服务器级别完成此操作:另请参阅 http:// wiki.apache.org/httpd/RewriteQueryString
To replicate the original setup you dond't need to involve PHP at all. You can accomplish this at the server level using some
RewriteRules
:See also http://wiki.apache.org/httpd/RewriteQueryString
查询字符串可以在
$_SERVER['QUERY_STRING']
中找到。The query string can be found in
$_SERVER['QUERY_STRING']
.在
mysite.com
域的旧主机上,在 DOCUMENT_ROOT 中创建一个 .htaccess 文件,如下所示:以上代码会将每个类似于
mysite.com?foo
的 URI 重定向到http://www.realsite.com/
,HTTP 状态代码为 301。?
最终将丢弃任何现有的 QUERY 字符串。On your old host for
mysite.com
domain create a .htaccess file in DOCUMENT_ROOT like this:Above code will redirect every URI that looks like
mysite.com?foo
tohttp://www.realsite.com/
with HTTP status code 301.?
in the end will discard any existing QUERY string.您的选择
是通过 mod_rewrite 捕获这些代码并将请求重定向到专门设置来处理这些旧版 url 的脚本。或者您可以修改index.php 脚本来查找代码并执行此时必须执行的操作。
would be the equivalent of doing
Your choices would be either to catch those codes via mod_rewrite and redirect the request to a script specifically set up to handle these legacy urls. Or you can modify the index.php script to look for the codes and do whatever it has to at that point.