1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to .htaccess redirect back from where visitor came?

Discussion in 'Apache' started by postcd, Sep 10, 2016.

  1. #1

    on the Apache server IP is installed SSL certificate for domain1.com, but other domains when not having certifficate and accessed via https, are redirecting to the domain1.com

    I can install SSL for all domains to prevent this, or use multiple IPs maybe, but i would rather use this way:
    The primary SSL domain for the server IP will have .htaccess (or index.php?) in its root to redirect all visitor back from where they come, only it will redirect to HTTP(not HTTPS), please how this htaccess or php rule would look like?

    http://domain0.com OK
    https://domain0.com --> https://domain1.com BAD
    Let domain1.com htaccess or index.php redirect visitor back to domain0.com:
    if referer contains https, then redirect back to referrer only replace https by http
    Code (markup):
    I was told there is no way to define this in the Apache, httpd.conf or such.

    This .php code seems to be working, but unsure if its good:
    $referer = $_SERVER["HTTP_REFERER"];
    $destination = str_replace("https", "http", $referer);
    if (strpos($referer, 'https') !== false)
    header("Location:". $destination);
    echo "http referer";
    Last edited: Sep 10, 2016
    postcd, Sep 10, 2016 IP
  2. postcd

    postcd Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    This worked, add following to the .htaccess file of the domain to which rest of the domains are redirected:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} =on
    RewriteCond %{HTTP_HOST} !^yourdomain.com
    RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
    Code (markup):
    change yourdomain.com to become domain to which rest of domains are redirected
    postcd, Sep 10, 2016 IP