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
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).
What @ThePHPMaster said is the correct way to do it. You can also use a generator such as: https://donatstudios.com/RewriteRule_Generator
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:
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?
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.
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