是否可以附加?ref=myref
到所有外部URL?
如果是这样,我猜我还需要检查?
已存在并使用&
如果是的话。
我是来自Joomla的WP noob,任何提示/帮助都将是非常热情的欢迎。:)
不确定是否可以在第页或.htaccess
.
是否可以附加?ref=myref
到所有外部URL?
如果是这样,我猜我还需要检查?
已存在并使用&
如果是的话。
我是来自Joomla的WP noob,任何提示/帮助都将是非常热情的欢迎。:)
不确定是否可以在第页或.htaccess
.
Inbound links = 从其他网站到您自己网站的链接。
Outbound links = 从您的网站到其他网站的链接。
一external link 将是指向除链接所在域以外的任何域的任何链接。
从你的评论来看,我猜你想要实现的是修改所有的出站链接。
正如@MrWhite所言,you will not be able to change your outbound links by modifying your .htaccess file (不过,如果您必须修改入站链接,这会很有帮助)。
现在,有几个解决方案可以为您提供:
document.addEventListener( "DOMContentLoaded", modify_outbound_links);
function modify_outbound_links(){
anchors = document.getElementsByTagName(\'a\');
for (let i = 0; i < anchors.length; i++) {
let p = anchors[i].href;
if (p.indexOf(\'yourdomain.com\') === -1) {
anchors[i].href = p + (p.indexOf(\'?\') != -1 ? "&" : "?") + \'ref=myref\';
}
}
}
向WordPress添加一些JavaScript的推荐(也是最干净的)选项是使用wp_enqueue_script. 如果您需要一个更简单的选项,只需将此代码段封装在<script> ... </script>
把它放在你的页脚里。php。在您的情况下,您可以使用\'the_content\' 过滤器,可用于在从数据库检索帖子后,以及在将其打印到屏幕之前,修改帖子的内容。
您需要将其添加到主题的函数中。php文件:
add_filter( \'the_content\', \'myprefix_modify_outbound_links\' );
function myprefix_modify_outbound_links( $content ) {
/* here you can search for all external links in $content and modify them as you wish */
return $content;
}
注意,这将过滤WordPress帖子中的所有链接。您可能希望搜索主题的代码,以防有其他外部链接。您可以检查请求标头是否包含http referer
, 然后检查http referer
标题来自外部站点,然后使用.htaccess
在内部重写url。但这并不能保证将所有外部URL检测为http referer
由于某种原因可能会被丢弃。
.htaccess
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !www.example.com [NC]
RewriteRule ^(.+)$ $1?ref=myref [QSA,L]
第1行检查请求标头http referer
不为空。然后第2行检查http referer
来自外部域。第3行重写所有url并附加查询字符串ref=myref
在内部,如果前两个条件满足。我有一个自定义的帖子类型“products”。我想将所有帖子从“产品”重定向到一个url,例如:http://example.com/page1 使用htaccess。例如:http://example.com/products/post1, http://example.com/products/post2 和http://example.com/products/post3 要链接,请单击重定向到一个页面http://example.com/page1选项+followSymLinksWriteEng