[英]How can I forward a dynamic URL to twitter using .htaccess or PHP?
I need to rewrite a dynamic URL.我需要重写一个动态的 URL。 The content
myurl
and mytext
is always different and should be insert in the "text" and "url" from the Twitter string.内容
myurl
和mytext
总是不同的,应该插入 Twitter 字符串的“text”和“url”中。
This is the string:这是字符串:
http://example.com/share/?myurl=http%3A%2F%2Fwww.example.com&mytext=helloworld
/* forward to: */
http://twitter.com/intent/tweet?related=Example%3Aname&text=helloworld&url=http%3A%2F%2Fwww.example.com&via=example
How can that be made?那怎么能做到呢? (I browsed the
.htaccess
suggestions but couldn't find a solution for my specific problem.) (我浏览了
.htaccess
建议,但找不到针对我的具体问题的解决方案。)
Does your server support PHP?您的服务器是否支持 PHP?
You could just put something like the following in a PHP file:您可以在 PHP 文件中添加如下内容:
Header("Location: http://twitter.com/intent/tweet?related=Example%3Aname&text=$_GET['mytext']&url=$_GET['myurl']&via=example");
It will be more efficient to handle it with rewrite Rules.使用重写规则处理它会更有效。
RewriteEngine On
RewriteCond %{QUERY_STRING} ^myurl=(.*)&mytext=(.*)$
RewriteRule ^(.*)$ http://twitter.com/intent/tweet?related=Example%3Aname&text=%2&url=%1&via=example [R,L]
If you want this to be permanent redirect then replace R with R=301.如果您希望这是永久重定向,请将 R 替换为 R=301。
With permanent redirects, these links will always be redirected by browser and your server will have to deal with less traffic if that is desired.使用永久重定向,这些链接将始终由浏览器重定向,如果需要,您的服务器将不得不处理更少的流量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.