1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

URL redirecting

Discussion in 'Black Hat SEO' started by Shibbi90, Apr 19, 2017.

  1. Shibbi90

    Shibbi90 Regular Member

    Joined:
    Mar 3, 2011
    Messages:
    387
    Likes Received:
    106
    Gender:
    Male
    Location:
    Norway
    Hey,

    I have multiple domains pointing to the same WP install. As of now you will see the same domain in the address bar as the one you click. Is there any way of showing only the main URL no matter what domain the visitors used to get to my website?

    I know I can use HTTP redirect with namecheap, but I don't really want to do that. I am currently using cloudflare as my DNS provider.

    I have tried 301 URL redirect with page rules on CloudFlare but I can't seem to get it working.

    Any help would be appreciated :)
     
  2. redarrow

    redarrow Elite Member

    Joined:
    Apr 1, 2013
    Messages:
    5,977
    Likes Received:
    1,444
    Yes use php reffreer and redirect to main url.
     
    • Thanks Thanks x 1
  3. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
    In the .htaccess file in each of the folders for each domain, create a 301 redirect to the main domain.
     
    • Thanks Thanks x 1
  4. pavan

    pavan Elite Member

    Joined:
    Mar 30, 2008
    Messages:
    1,819
    Likes Received:
    457
    you can add the domains in your cpanel and use redirect option from there
     
    • Thanks Thanks x 1
  5. redarrow

    redarrow Elite Member

    Joined:
    Apr 1, 2013
    Messages:
    5,977
    Likes Received:
    1,444
    <?php
    if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != "http://www.bad.com"){
    $url = $_SERVER['HTTP_REFERER'];
    }else{
    $url = "Http://www.good.com";
    }

    header("Location: ".$url);
    ?>

    Should work on a phone sorry.
     
    • Thanks Thanks x 1
  6. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
    This is totally doable, but it's way slower than doing it at a lower layer such as .htaccess. At the application layer, you have to load up a lot more infrastructure before the redirect finally takes place.
     
    • Thanks Thanks x 1
  7. Shibbi90

    Shibbi90 Regular Member

    Joined:
    Mar 3, 2011
    Messages:
    387
    Likes Received:
    106
    Gender:
    Male
    Location:
    Norway
    Do you have an example for 301 redirect with .htaccess or a link for more info? :) Total newbie here. Googling as we speak
     
  8. redarrow

    redarrow Elite Member

    Joined:
    Apr 1, 2013
    Messages:
    5,977
    Likes Received:
    1,444
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} .*zzz.com.*$
    RewriteRule ^(.*)$ http://good.com/
     
  9. redarrow

    redarrow Elite Member

    Joined:
    Apr 1, 2013
    Messages:
    5,977
    Likes Received:
    1,444
    • Thanks Thanks x 1
  10. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
  11. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
    • Thanks Thanks x 1
  12. redarrow

    redarrow Elite Member

    Joined:
    Apr 1, 2013
    Messages:
    5,977
    Likes Received:
    1,444
    Speed is milosecounds these days ....both header solution , in fact php might be quicker if wp being used .
     
  13. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
    I agree that the difference would be milliseconds, but there is absolutely, literally no way a PHP redirect can be faster than an htaccess redirect. When the connection comes into the server, it checks htaccess, then proceeds to execute the application layer which includes creating the PHP session, etc. WordPress would have no bearing on whether PHP is faster. In fact, most plugins such as Yoast, handle the redirects inside the .htaccess file.
     
  14. redarrow

    redarrow Elite Member

    Joined:
    Apr 1, 2013
    Messages:
    5,977
    Likes Received:
    1,444
    Give me that brain lol , i agree you win lol interesting cheers
     
  15. Shibbi90

    Shibbi90 Regular Member

    Joined:
    Mar 3, 2011
    Messages:
    387
    Likes Received:
    106
    Gender:
    Male
    Location:
    Norway
    Thanks guys, this was a lot easier than I thought! Already managed to redirect 1 domain :) Do I just use the code below over and over again for all domains or is it possible to add more domains within this code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.example.com [NC]
    RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]
     
  16. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
    You can put 1 .htaccess file in your root folder and it will apply to all requests that come in. I prefer putting them in each domain folder for organization's sake and if you kill off a domain, you don't have needless htaccess rules.
     
  17. Shibbi90

    Shibbi90 Regular Member

    Joined:
    Mar 3, 2011
    Messages:
    387
    Likes Received:
    106
    Gender:
    Male
    Location:
    Norway
    I only have 1 .htaccess file and 1 root folder, but lots of domains pointing to that root folder. So should my .htaccess file look like this?

    Or is it possible to add more domains within the code "RewriteCond %{HTTP_HOST} ^example1.com [NC,OR]" with something separating the domains?
     
  18. SEO

    SEO Jr. VIP Jr. VIP

    Joined:
    Jan 6, 2017
    Messages:
    865
    Likes Received:
    650
    Yeah, I think something like this should work:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example1.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.example1.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^example2.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.example2.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^example3.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.example3.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^example4.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.example4.com [NC]
    RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]
     
    • Thanks Thanks x 1