Wordpress 屏蔽所有传出链接
我有一个软件下载站点,所有软件都托管在AmazonS3上。我在我的网站上使用WordPress,我不想让我的访问者知道我在AmazonS3上托管了所有的软件。我想将所有AmazonS3URI重写到我的站点url,每当访问者单击这些URI时,他们都应该重定向到AmazonS3 我尝试了Pretty Links Lite插件来隐藏AmazonS3链接,但该插件速度非常慢,而且缺乏支持Wordpress 屏蔽所有传出链接,wordpress,.htaccess,url,rewrite,mask,Wordpress,.htaccess,Url,Rewrite,Mask,我有一个软件下载站点,所有软件都托管在AmazonS3上。我在我的网站上使用WordPress,我不想让我的访问者知道我在AmazonS3上托管了所有的软件。我想将所有AmazonS3URI重写到我的站点url,每当访问者单击这些URI时,他们都应该重定向到AmazonS3 我尝试了Pretty Links Lite插件来隐藏AmazonS3链接,但该插件速度非常慢,而且缺乏支持 有人对如何实现这一点有什么建议或更好的建议吗?除非你想通过服务器进行流式下载,这会破坏在Amazon S3上的托管点
有人对如何实现这一点有什么建议或更好的建议吗?除非你想通过服务器进行流式下载,这会破坏在Amazon S3上的托管点,你将无法掩盖你的下载在Amazon S3上的事实。加入游戏有点晚,但我在Pretty Links Lite上遇到了同样的问题。你添加的链接越漂亮,你的网站速度就越慢,即使是在高速缓存的情况下 我的解决方案是创建一个名为redirect的自定义post类型,并使用一些自定义字段,尽管我使用高级自定义字段插件来获得更优雅的后端体验。然后简单地添加一个快速函数,该函数钩住模板_重定向,检查您的帖子类型 唯一的缺点是您需要为CPT分配一个slug,但是您可以在register函数中轻松地自定义它 这是我的密码:
function register_redirect_cpt {
register_post_type('redirect', array(
'label' => 'redirects',
'labels' => array(
'name' => 'Redirects',
'singular_name' => 'Redirect',
'add_new' => 'Add Redirect',
'add_new_item' => 'Add New Redirect',
'edit_item' => 'Edit Redirect',
'new_item' => 'New Redirect',
'view_item' => 'View Redirect',
'search_items' => 'Search Redirects',
'not_found' => 'No Redirects found',
'not_found_in_trash' => 'No Redirects found in Trash'
),
'description' => 'Pretty Redirects',
'public' => true,
'menu_position' => 5,
'supports' => array(
'title',
'author',
'custom-fields' // This is important!!!
),
'exclude_from_search' => true,
'has_archive' => false,
'query_var' => true,
'rewrite' => array(
'slug' => 'redirect',
'with_front' => false
)
));
}
add_action('init', 'register_redirect_cpt') ;
正如我所说,您可以使用自定义字段或ACF插件来设置一些元盒–1个用于公共链接,另一个用于真正的目的地。我假设您使用香草自定义字段。然后将其插入functions.php或主题函数文件:
function redirect_for_cpt() {
if (!is_singular('redirect')) // If it's not a redirect then don't redirect
return;
global $wp_query;
$redirect = isset($wp_query->post->ID) ? get_post_meta($wp_query->post->ID, '_true_destination', true) : home_url(); // If you forget to set a redirect then send visitors to the home page; at least we avoid 404s this way!
wp_redirect(esc_url_raw($redirect), 302);
exit;
}
add_action('template_redirect', 'redirect_for_cpt');
@然后,您需要通过您的站点流式下载。