Website self-referral - .htaccess

Google Analytics is showing my own root domain is the referral for a large portion of my website's traffic.
So, mywebsite.com is showing as the referrer for www.mywebsite.com.
I have tried adding a referral exclusion within Analytics with no success. I have cleaned my .htaccess which also hasn't been successful
.htaccess code
RewriteEngine On
Options +FollowSymLinks
# Redirects mywebsite/uk/anypage to mywebsite.eu/anypage
RewriteRule ^uk/(.*)$ /$1 [NC,R=302,NE,L]
# Redirect 404 to index
ErrorDocument 404 /
# Use www version
RewriteCond %{HTTP_HOST} ^mywebsite.eu [NC]
RewriteRule ^(.*)$ http://www.mywebsite.eu/$1 [L,R=301,NC]
This is what it looks like in Analytics:
I've put a lot of time into trying to find the cause so any suggestions, .htaccess related or otherwise, are very welcome

Did you migrate recently to Universal Analytics? It migrates the previous utmz cookie values that stored traffic source, so if your users had self-referrals prior to upgrading to UA, this will persist int your data. Could you check if there are new sessions in this traffic?

Make sure to add to the referral exclusion list your domain with and without the www.
For some reason certain sites it likes to have it while on others it does not, I would definitely try this and then see if the future sessions are any more clean before changing too much with the .htaccess.

Related

Rewrite a complex link .htaccess

My old website have product link like this
domain-name/index.php/product-category/detail/603/product-name.html
my new Wordpress website have product link like this
domain-name/product-category/product-name
i config in .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^product-category/detail/([0-9]+)/([a-zA-Z-]*).html /product-category/$2 [QSA,L]
in permalink i config:
/%category%/%postname%
The new site works very correctly, but the old link is not working. Old link always redirect to error 404 absolute, i want to keep old link on google auto redirect to new link. Does anyone have a solution for this please, thank u very much.
This should be your rule modified to actually match the requested URL you show:
RewriteEngine On
RewriteRule ^/?index\.php/product-category/detail/\d+/([\w-]+)\.html /product-category/$2 [QSA,END]
But more likely you want the more flexible variant:
RewriteEngine On
RewriteRule ^/?index\.php/([\w-]+)/detail/\d+/([\w-]+)\.html /$1/$2 [QSA,END]
You should prefer to implement such rules in the actual http server's host configuration. If you have no access to that you can use a distributed configuration file (often called ".htaccess"), but that comes with some disadvantages.
I could imagine that it also makes sense to send an external redirection to clients still requesting those old URLs:
RewriteEngine On
RewriteRule ^/?index\.php/([\w-]+)/detail/\d+/([\w-]+)\.html /$1/$2 [QSA,R=301,END]
For that it might make sense to start out with a R=302 temporary redirection and to change that to a R=301 permanent redirection once you checked that everything works as expected. That prevents annoying caching issues...

How to redirect a new page (wrong URL) to another page?

I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]

Redirect scam domain to warning?

A client of mine has found out today that someone has set up a spoof domain (1 letter different - design instead of designs) and has tried to set up credit accounts in his name.
The domain will undoubtedly be removed, but is it possible in the meantime using some htaccess trick to check if a visitor to www.designs.com has been referred from www.design.com and if they have, send them to a warning page?
You can use this code in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http(s)?://([^\.]+\.)?design\.com
RewriteRule ^.* /warning.html [L,R=302]
It will redirect any pages coming from design.com and its possible subdomains (using http or https) to a page named warning.html at the root of your project.
You can test this rule with this online tool.

.htaccess to prevent hitbots URI "payday" and "loans"

One of my Drupal servers was recently hacked. Although it's clean now, I get lots of Google traffic for /payday-loans and /leasehold-loans
and similar. They have generated enough traffic to slowdown my website and especially mysql. What is the correct code for .htaccess to redirect (or just stop) all URIs containing payday or loans? I'd like to handle these requests at the apache level--prior to PHP and mysql processing them.
Try adding this above any rewrite rules that you may already have:
RewriteEngine On
RewriteRule (?:payday|leasehold)-loans - [L,F]
This will return a 403 forbidden, but you may want to redirect to something else instead.
RewriteEngine On
RewriteRule (?:payday|leasehold)-loans https://google.com/ [L,R=301]
This redirects any request with payday/leasehold-loans to google, or you can just 404 it:
RewriteEngine On
RewriteRule (?:payday|leasehold)-loans - [L,R=404]

Want to redirect domain to blog in subfolder until full site launches

I am in the process of launching a full website that will be ready in about 6-9 months but I have a self-hosted Wordpress blog created in the meantime to start building a userbase and SEO. So since there will eventually be more to my site than a blog, my blog is located in a subfolder in my root domain (www.website.com/blog). I would like for my root domain (www.website.com) to automatically send users to my blog (www.website.com/blog). Once the full site is ready, I then want my users to enter my domain and be sent to the regular site and not the blog.
Through my searching, it seems like I will either have to set up a 301 or 302 redirect, which I understand how to do. The question is which one to use to prevent negative SEO once the full site launches. I have a feeling I should use a 302 redirect since it is a temporary redirect, but from what I have been reading, it seems like this may hurt my SEO on the popular search engines.
Your help would be greatly appreciated and I can provide more details if needed. Thanks!
I would suggest not to use external redirect and handle this via internal redirect only. That way your URL never changes and search engines will not index wrong URL. In your .htaccess put these rules for this purpose:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/+blog [NC]
RewriteRule ^(.*)$ blog/$1 [L,NE]
RewriteRule ^(/)?$ /blog [R=302]
That should do the trick.

Resources