Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    On Apache servers, they usually have the mod_rewrite module enabled, which means you can add rewrite conditions and rules in .htaccess to manage such redirects. There’s no point in involving WP if you are redirecting to another site.

    With rewrite rules you can use regexp syntax to capture parts of the request and use those parts in the new URL.

    Thread Starter Mazzo77

    (@mazzo77)

    thanks a lot for replying me

    but actually i find this way is so hard to apply

    well, there’s something into my mind; can i have a unique URL and then redirect it through my index.php

    for example , i will insert the URL : https://www.mydomain.com/123 in all my posts

    and will have a redirected code in my index.php

    <
    header("Status: 301 Moved Permanently");
    redirect ("www.mydomain.com/123");
    header("Location:https://www.google.com/<POST_TITLE>");
    exit;
    ?>

    where <POST_TITLE> is my posts titles

    so, when a user is on my site and he enters a post called “Welcome” and the user clicked on the url : https://www.mydomain.com/123 , he will auto redirected to https://www.google.com/Welcome

    is this possible ?

    thnx in advance

    • This reply was modified 7 years, 3 months ago by Mazzo77.
    • This reply was modified 7 years, 3 months ago by Mazzo77.
    • This reply was modified 7 years, 3 months ago by Mazzo77.
    Moderator bcworkz

    (@bcworkz)

    Sure! You don’t need a redirect call, the headers do that. You need a conditional that checks the request in $_SERVER[‘REQUEST_URI’] before sending headers. Headers must be sent before any output from templates.

    I suggest you put your code in wp-config.php so WP does not need to load if there will be a redirect. Code here must be pure PHP, WP functions are not yet available.

    Thread Starter Mazzo77

    (@mazzo77)

    thnx a lot

    but can you kindly help me to write this PHP code, if possible ?

    i have poor skills in PHP

    thnx in advance

    Thread Starter Mazzo77

    (@mazzo77)

    hi

    i was using some affiliate links of a site and with different links in my posts but adblocker has blocked the links

    for example :

    i have a post saying about movie called dunkrink and i have an affiliate link in the post (wordpress) : https://www.affiliate.com/dunkrink

    and in another post i have: https://www.affiliate.com/batman

    adblocker has blocked the domain : affiliate.com , so i lost all my links and users with adblocker cannot see the links

    is there any possibility to make a trick like the following

    replace the domain : affiliate.com in all my posts with : https://www.mydomain.com/aff

    and then redirect the domain “www.mydomain.com/aff/%” to “affiliate.com”

    do you understand me ?

    i want to just redirect the domain and the new URLs will be vaild

    new urls will be

    https://www.mydomain.com/aff/dunkrink

    https://www.mydomain.com/aff/batman

    is this possible ?

    Moderator bcworkz

    (@bcworkz)

    Sorry for the slow reply. If altering links to evade ad blockers is your goal, the redirects we’ve discussed earlier will be more likely to work than changing the links client side. Client side changes are done through JavaScript. It may be that ad blockers scan for JS changes and as soon as you update the link, it will be removed.

    However, I think with a server side solution, the referrer then becomes your server and multiple requests from the same referrer are likely denied affiliate credit as a measure to prevent click fraud. You are welcome to try anyway, who knows, maybe it’ll work. Ad blockers, as you know, are a big problem for monetizing content. If it were this easy to evade blockers, everyone would be doing it. I suspect your solution will need to be much more sophisticated to work.

    There’s no harm in trying though. Unfortunately, I’m not able to help you with the code. Even though you found a .htaccess solution hard to apply, it’s probably the most likely approach where you can find decent examples through searching that could be adapted to your needs. Rewrite rules are notoriously difficult to debug when you get them wrong. The general approach is to keep trying variations until it works. It’s as much perseverance as skill. Apache can be configured to generate trace logs. These logs are difficult to interpret, but can be very helpful in debugging. Good luck!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘set a dynamic redirected link ?’ is closed to new replies.