Significant drop in Google search apperance after switch to https - .htaccess

I have what I can say is a huge problem. I have a website that I've switched to https using Cloudflare and it almost completely disappeared from Google search results.
Here is my .htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
So I have 301, but did I do it right?

Google may some time to reindex. According to this discussion on Moz, it may take a day for important URLs to 90 days for less important URLs to be indexed.
Other than that, it seems that you have only just changed the .htaccess to 301 redirect all URLs to the https one.
Have you:
check Google Webmaster Tools to see if the site has been indexed and for any error messages?
Changed the links in the sitemap.xml to the https one?
Updated the rel=canonical tag?
Changed all the internal URLs to https?
Updated other rel tags like rel=next, rel=previous and rel=alternate?
Updated all the external URLs you control, like Facebook/ Twitter?
Updated things like open-graph tags and social media widgets, so that new link juice can be passed on to the new https site when others share on social sites?

You probably want to indicate in GWT that you would prefer to use https://.

Related

.htaccess: rewriteCond to another page within same URL with params

I've an condition for my .htaccess for crawlers and search engines which takes them to a "static" page where they can scrape all content.
Up until now I've had my domain {client}.realdomain.com where {client} is a subdomain for one client.
When the client then shares something on a social network, e.g. facebook/linkedin their crawlers are taken to my .htaccess which have following conditions (and this works)
URL example: http://{client}.realdomain.com/s/token
RewriteCond %{HTTP_USER_AGENT} (LinkedInBot/[0-9]|facebookexternalhit/[0-9]|Facebot|Twitterbot|twitterbot|Pinterest|pinterest|Google.*snippet|baiduspider|rogerbot|embedly|quora\ link\ preview|showyoubot|outbrain|slackbot|vkShare|W3C_Validator)
RewriteCond %{HTTP_HOST} ^(.+?)\.realdomain\.com$
RewriteRule ^s/(.*)$ http://%1.realdomain.com/static.php?token=$1 [NC,L]
will end up as http://{client}.realdomain.com/static.php?token=token
As said, anything here works perfect but now I'm moving into having different domains, so it can be
{client}.real-domain.com and {client}.sunset.com
I essentially what the same thing in my .htaccess but it should take the whole domain with it when it redirects so it will go to e.g. http://{client}.sunset.com?static.php=token=my-secret-token if a crawler comes to {client}.sunset.com/s/my-secret-token
How would I got about doing this? I seem to be a simple solution but for some reason I just can't seem to get my head around it.
Thanks
RewriteCond %{HTTP_USER_AGENT} (LinkedInBot/[0-9]|facebookexternalhit/[0-9]|Facebot|Twitterbot|twitterbot|Pinterest|pinterest|Google.*snippet|baiduspider|rogerbot|embedly|quora\ link\ preview|showyoubot|outbrain|slackbot|vkShare|W3C_Validator)
RewriteCond %{HTTP_HOST} ^(.+?)\.%{HTTP_HOST}%\.com$
RewriteRule ^s/(.*)$ http://%1.%{HTTP_HOST}%.com/static.php?token=$1 [NC,L]
Can you test this out? By replacing your domain name with %{HTTP_HOST}%

301 Redirect from http to https and new page name

I have a site that is going from a non secure HTML/PHP site to a secure Wordpress site. All pages are changing. Also going from www to non-www.
So as an example
http://www.sitename.com/contact.php
will become
https://sitename.com/contact-us/
I know how to do a typical redirect in .htaccess:
Redirect 301 /oldpage.html http://www.example.com/newpage.html
But I'm not sure how to do this when both the page location and the HTTP/HTTPS is changing as well as the www going away. The site ranks pretty well and I don't want to lose any of that.
I've researched but can't find an example of doing both at the same time.
You should be able to do using rule like this:
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^contact\.php$ https://%1/contact-us/ [R=301,L,NC]
Since your page names are different you will need multiple rules like this.
Make sure to keep these rules above all other rules.
You can use the following :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^contact\.php$ https://example.com/contact-us [NC,L,R=301,NE]
The rule above rewrites the following requests :
http://www.example.com/contact.php
or
http://example.com/contact.php
or
https://www.example.com/contact.php
to
https://example.com/contact-us

Redirect all but one page to http from https

For reasons of SEO, I would like to redirect all but one of the pages of my website from https to http. Currently, if you visit the https:// version you are presented with my website and the aforementioned prefix is in the address bar. If you visit the http:// version the https:// prefix is absent. Apparently, as a result, Google treats my site as if it were two identical sites. Not good for SEO.
St.Woland's answer here was very helpful in redirecting almost all the pages of my website from https to http. In fact, it worked like a dream until I tried visiting the one page that needed to have the secure connection.
Before trying his fix, were you to visit the secure basket page the whole page was marked as secure. However, with the recommended .htaccess fix in place, all images and css were flagged as insecure and Chrome refused to load them; the page looked a mess.
It seemed like an article on Best Host Ratings had the solution: add further .htaccess files to the images and css folders and all would be well.
Sadly, this then meant that those pages without the https:// prefix did not load the css or the images.
Please see below the code I put in. Firstly, the .htaccess to redirect all but the basket page from https to http:
RewriteEngine On
RewriteBase /
# Turn SSL on for basket
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/basket\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Turn SSL off everything but basket
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/basket\.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Secondly, the .htaccess I placed in the images directory:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} images
RewriteRule ^(.*)$ https://www.domain.com/images/$1 [R,L]
An obvious solution to this situation might be to just redirect the whole site across to the https version. But, placed at the base of all pages except the basket page is script from Google AdWords that places relevant ads across the internet after users have visited my site. This script is flagged as insecure.
Any help with this issue would be most appreciated.
With kind regards,
Mark

How to redirect a first time visitor using htaccess

How to redirect a first time user to a special landing page using htaccess based on referrer? I mean if they came from another domain then they are the first time visitor?
I am really noob at url rewriting and explanation would be great .
Note: the landing page is nothing but a php script that detects browser. On that page I will use cookie, but need to redirect the user if the referrer is empty or its from another domain.
I suggest this :
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^(www\.)?(https?://)?example\.com[NC]
RewriteCond %{REQUEST_URI} !^/welcome.html [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,L]
The first RewriteCond check if referer contains your domain name, and the second check if you are not just redirected by the RewriteRule.
The RewriteRule brings you to the welcome page as a [L]ast rule.
How about redirect the use if his referer is not your domain ?
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(www\.)?(https?://)?(?!example\.com) [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,NC]
That means that the user will be redirected to welcome.html if he writes example.com in the address bar or comes from a link in another site. Once on your site it won't be redirected anymore if he load another page in your site.
P.S. AFAIK you can use cookies in PHP that generates a plain html page see here
Edit: Update tested code
Excuse my reheating the old steak once more.. I would still be interested in knowing if anyone knows the solution to this problem - without using cookies or HTML5 features...
I have read here that the HTTP_REFERER might be blank. Is that why this method of redirecting is not good for this application? I have experimented with this on my server but the closest result working result was being always redirected to my landing page index.htm, which is not desired..
Could this rule interfere with other rewrite rules?
Also, there is an error in the former snippet:
And I think the NC flag in the latter snippet does not make sense. Should it not be L?
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^(www\.)?(https?://)?example\.com[NC]
#missing space after .com and before [----------------here----^
RewriteCond %{REQUEST_URI} !^/welcome.html [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,L]
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(www\.)?(https?://)?(?!example\.com) [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,NC]
#Should this flag not be L? ------------------------------^

URL Rewrite seems to be functioning like a URL Redirect

This is the rewrite section of my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^komarketingassociates\.com$ [NC]
RewriteRule ^(.*)$ http://www.komarketingassociates.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteRule ^industry-news/.*[$]([0-9]+)\.htm$ http://www.komarketingassociates.com/industry-news/article.php?articleid=$1 [L]
The last rewrite rule is meant to process requests for our repository of news articles. Until maybe a week ago it was working perfectly translating the SEO friendly link titles like this one, companies-are-becoming-more-accustomed-to-leveraging-social-media$715.htm into the proper format to retrieve them from the database. Recently, however, without any changes being made to the .htaccess file (to my knowledge) the links now seem to use this redirect to article.php?articleid=715 rather than doing it server side. The links on the site are still the seo friendly urls, but now it seems as if you are being redirected to the article template page.
We are using GoDaddy to host our site. PHP version 5. I am completely stumped as to how this is happening and how to fix it. Any help is appreciated!
Thanks!
-Bill
Proxy flag. (P)
Warning, will mess with IPs. Every single IP will look like it's your servers. However, mod_rewrite sets the X-FORWARDED-FOR when you use P, so you can extract (I'd recommend validating the IP as being real as well before trying to use it in any SQL) and use the IP address still.

Resources