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.

.htaccess redirect + counting traffic

Discussion in 'PHP' started by postcd, Mar 21, 2014.

  1. #1
    Hello,

    i have old domain with subpages and subdomains. I want to redirect 301 all old domain pathes to new domain "/" (meaning index)

    what is the best .htaccess rule to use?

    At same time i would like to discover how much traffic goes from old domain, how to do it?

    thank you
     
    postcd, Mar 21, 2014 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    To redirect all traffic to new domain root:

    
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://www.newdomain.com/?d=1 [R=301,L]
    
    Code (markup):
    In your new domain main page, have a counter that checks for $_GET['d'] == 1 and when true increment counter (either file based counter or DB counter).
     
    ThePHPMaster, Mar 21, 2014 IP
  3. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #3
    Good, but im not a programmer and i wont hire anyone.
     
    postcd, Mar 21, 2014 IP
  4. MikeLugar

    MikeLugar Well-Known Member

    Messages:
    1,453
    Likes Received:
    36
    Best Answers:
    2
    Trophy Points:
    150
    #4
    MikeLugar, Mar 21, 2014 IP
  5. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #5
    Here is a simple counter you can use (in no way this is the perfect solution, but for free it is good enough):

    
    <?php
        if ($_GET['d'] == 1) {
            $count = file_get_contents('counter.txt');
            file_put_contents('counter.txt', ++$count);
        }
    
    PHP:
     
    ThePHPMaster, Mar 21, 2014 IP
    postcd likes this.
  6. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #6
    issue is that i currently have .htaccess redirect on my old domain, so i dont know where to put above counter code if i wish to land people to my index page of a new domain?
     
    postcd, Mar 22, 2014 IP
  7. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #7
    That code will go into your index.php on the destination URL.
     
    ThePHPMaster, Mar 22, 2014 IP
  8. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #8
    Thank you, i did it thanks to you

    1. old domain .htaccess:

    2. newdomain created counter.txt file and chmod 777

    3. added following code to the index.tpl file

    And it counts :)

    One more think i want to ask: that htaccess redirect 301 isnt it wrong somehow that it leads to url which is not defined in destination index file? (?go=home) i mean if it anyhow dont harm 301 google link juice.
     
    postcd, Mar 22, 2014 IP
  9. akshat113

    akshat113 Member

    Messages:
    17
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    33
    #9
    I can code it for you... foor more info mail me at
     
    akshat113, May 1, 2014 IP
  10. Jigney

    Jigney Active Member

    Messages:
    168
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    93
    #10
    To redirect all your old domain url to new domain url, you have to use this code in your HTACCESS

    RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
    RewriteRule ^(.*)$ newdomain.com/$1 [R=301,L]

    It will redirect all your old domain url to new domain, Either that url is exist or not, and it's not exist than it's 404 and definitely it's bad for SEO so, to solve this issue you have to use Rewritemap,

    have a look at Rewritemap

    apache.org/docs/current/rewrite/rewritemap.html
     
    Jigney, May 16, 2014 IP