简体   繁体   中英

Redirect wordpress home page by referrer http request

I need to redirect to a static *.html page my wordpress homepage when the http request come from instagram website. I tried to add this code in a custom plugin, but it doesn't work:

add_action('template_redirect', 'redirect_ref');
function redirect_ref () {
    $referer = wp_get_referer();
    if (is_home() && strpos(parse_url(wp_get_referer())['host'],'l.instagram.com'))){
        wp_redirect('/custom_page.html');
}

i think i understood your problem.

The best way is to solve it via a get parameter. You can add this to your .htaccess file

RewriteEngine on
RewriteCond %{QUERY_STRING} inst
RewriteRule ^$ /example.html? [L,R=301]

and link your webpage with this link:

www.yourpage.de?inst

and it will redirect to www.yourpage.de/example.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM