.htaccess which somehow prevents Google to put some PageRank on my domains - .htaccess

I am using the following .htaccess code on all my domains since 2+ years ago on some projects, but no one of the websites build has ever got any Google PageRank, at least '1' bar. On all websites on which I don't use this code, I am getting a reasonable PageRank.
Could you tell me what I am doing wrong:
RewriteEngine On
RewriteBase /
# rewrite the non 'www' addresses
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# rewrite REQUEST_URI
RewriteCond %{HTTP_HOST} ^www\.example\.com [OR]
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) index.php [L]
some of my websites using this .htaccess:
http://www.kampril.bg/
http://www.milleniumbg.eu/

Register these domains in the Google Search Console and check whether Google returns some error messages or some feedback about these. Submit some sitemaps.
If you do not see any error messages or warnings, then it simply means Google does not find the content of your websites interesting.

Related

Forced SSL in htaccess going to only the home page

I have recently added an SSL to my sites. I have added the code to the .htaccess file to force the https. The issue is that my external links that go to pages within the site are now being redirected to the homepage. The code I am using is:
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www.watsonelec.com%1 [R,L]
I think the issue is in the last line, as the rule is telling it to redirect to the homepage. What I can't seem to find is a rule that will say for it to go to the URL provided in the link but give it an https instead of the HTTP.
I did do a search for this topic, but all the code I found was similar to what I already had. Thank you for all your help.
Update
I have two sites I am trying to work this out for, watsonenerysolutions.com and watsonelec.com.
When I tried
RewriteOptions InheritDownBefore
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www.watsonenergysolutions.com/$1 [R,L]
It still sent to the homepage
When I tried
RewriteOptions InheritDownBefore
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^ https://www.watsonenergysolution.com%{REQUEST_URI} [R,L]
I received an error message that said Safari can't open the page "https://www.watsonenergysolutions.com/index.php" because Safari can't find server "www.watsonenergysolutions.com"
%N backreferences are what you match in RewriteCond's. In your case, it is empty. That's why anything is going to the homepage.
You need to use $1 or %{REQUEST_URI}, both rules below are equivalent (the second may be faster because you don't -re-match unnecessarily)
RewriteRule ^(.*)$ https://www.watsonelec.com/$1 [R,L]
RewriteRule ^ https://www.watsonelec.com%{REQUEST_URI} [R,L]
Note 1: %{REQUEST_URI} value always begins with a leading /, while what you can match in a RewriteRule never begins with a leading /
Note 2: R flag uses a 302 redirect by default. Maybe you'll want to use a 301 ([R=301,L])

Domain redirection with folder separation. htaccess

After redirecting my client domain to my server i created rewrite rule in root folder .htaccess file to point domain to a subfolder1 (joomla website):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subfolder/
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Everything worked fine but today i found out that i can access any other subfolder in my server by entering for example: myclientdomain.com/subfolder2 and what's worse google can index that and show it in search results.
If there is any way to redirect a domain in a way that I won't be able to access any other folder on my server?
I would really appreciate help as I searched throughout google for answer, my server tech support said that they don't really support these kind of problems (they only gave me a piece of code from above) and I don't really know anything about .htaccess rules and how it works.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder\/?(.*)?$
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Change above rule to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
# if current URI is not starting with /subfolder/ then route to /subfolder/
RewriteRule ^((?!subfolder1/).*)$ subfolder1/$1 [L,NC]

redirect users by language - too many redirects

I am trying to redirect users with Chineses languages to the a domain using the following code in an .htaccess file
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (zh) [NC]
RewriteRule ^(.*)$ http://www.example.com/under_c.html [L]
When I change my browser language to Chinese and test out the redirect it does go to the specified page, but it doesn't display anything it just gives me an error in the console that says "Failed to load resource: net::ERR_TOO_MANY_REDIRECTS". I've tried other solutions around the web but none of them seem to be able to redirect by language.
Is there a better way to redirect by language in the .htaccess file?
To prevent a rewrite loop you need to exclude under_c.html from the rule.
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (zh) [NC]
RewriteCond %{REQUEST_URI} !=/under_c.html [NC]
RewriteRule ^ http://www.example.com/under_c.html [R=302,L]

htaccess help! wildcard subdomain rewrite rule to a specific folder for only some subdomains

Through a little research I came up with an htaccess rewrite rule in my development directory that takes a wildcard subdomain to its matching instance name in my development folder. I will admit I know little to nothing about this so help is really needed. So the current htaccess behaves as such:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomain\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [QSA]
example
instance_folder_name.mydomain.com
redirects to
public_html/development/instance_folder_name
this works great because it allows me to have development websites in the development directory and i dont have to be constantly creating subdomains for each site.
the problem I am having is how to approach the following scenerio:
I use virtual domains as an add on component in Joomla so that several domains are being managed by one single Joomla install. So i may have the following subdomains...
client1.mydomain.com
client2.mydomain.com
client3.mydomain.com
that all need to go to
/public_html/development/client1
I guess what i need is a general rule on how to handle all wildcard subdomains, but with exceptions for client1, client2, client3 for example
You can have a separate rules for these 3 subdomains and add an exclusion condition in the older rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(client1|client2|client3)\. [NC]
RewriteRule ^((?!client1/).*)$ /client1/$1 [L,NC]
RewriteCond %{HTTP_HOST} !^(client1|client2|client3)\. [NC]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomain\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [L]

How to apply a htaccess only when arriving on the website?

Let me explain the problem. We have a website in 2 languages: fr & nl (dutch).
When you arrive on our website, you land on www.domain.be which redirects
you (as you can see in the following code) to the dutch version if your browser language
is set to 'nl' and if it's set to 'en' (because dutch people often use this language for they browser) or leave you on www.domain.be / fr.domain.be (both url are work to call the website - the fr... one is more in response of the nl... one)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^nl [NC]
RewriteRule ^$ http://nl.domain.be/ [L,R]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ http://nl.domain.be/ [L,R]
</IfModule>
On the website, you can choose, by clicking on 2 links (in the top right corner), if you want to go to fr.domain.be or nl.domain.be.
When you click on one of those link, the htaccess redirects you even if you want to go to the fr part (while navigating on the dutch one) and the same on the nl part.
How can I solve that? I would like the htaccess to only redirect you when you first come to the website but then be desactivated and allow the user to choose his language if he wants to.
Could you please help me? I'm on this for like two days...
You're only redirecting the site base /, so swith directly to another page should not be a problem.
Can't you just use a fake index page when you manually switch ? Like http://nl.domain.be/index
You can create multiple conditions for a rule set so you could add an aditional check that the redirect only happens when you do not match the HTTP_REFERER to your domains.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^nl [NC]
RewriteCond %{HTTP_REFERER} !^*\.domain\.be/ [NC]
RewriteRule ^$ http://nl.domain.be/ [L,R]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteCond %{HTTP_REFERER} !^*\.domain\.be/ [NC]
RewriteRule ^$ http://nl.domain.be/ [L,R]
</IfModule>
the ! means NOT so basically you are saying when the HTTP_REFERER does NOT match the url pattern, which is "(wildcard).domain.be".
This will prevent the rule from being run if they are on your site currently and trying to change the language.
NOTE: I'm not near an apache box to test this so my syntax might be off but that should get you down the right path.

Resources