.htaccess rule not being followed only when coming from google

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 1643 Views - Last Post: 20 May 2015 - 06:27 AM

#1 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

.htaccess rule not being followed only when coming from google

Posted 17 May 2015 - 08:08 PM

I had a .htaccess rule created for me by my hosting company.

It is a very simple one rule and condition rule to re-route all of my pages show up at https.

RewriteEngine On
 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]


Initially the created the file as https://www.example.com. This caused my issues and took me forever to figure out that was the issue to my problems. It was causing my session to end and a new one would start. It also made anyone have to try logging in twice before they were able to login.

Now that I changed the file and took out the www the login and session issues are no longer present....except whenever I type my website into google and go to my site from there. Google still displays the site as https://www.example.com.

Shouldn't my rewrite rule make any entrance to my site be without www?

If not, how can I create it that www. redirects to not having it. I can't have customers/users not be able to login on the first attempt.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: .htaccess rule not being followed only when coming from google

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5342
  • View blog
  • Posts: 14,235
  • Joined: 18-April 07

Re: .htaccess rule not being followed only when coming from google

Posted 17 May 2015 - 08:24 PM

Well typically you just need this rule...

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]



Here you are saying if the host has "www" in it, instead write it without the www. I also suggest you make it a 301 redirect so that Google will then update its index to the one without "www" on its next indexing.

Edit: For the http to https you could also try...

ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L] 



Make sure that apache is also enabled to do rewriting.

a2enmod rewrite


:)

This post has been edited by Martyr2: 17 May 2015 - 08:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 17 May 2015 - 08:46 PM

Ok what I did was take out the code I had and entered this in and it made the site come up as only example.com. So it isn't allow my https to be in the browser. I changed the HTTP_HOST to HTTPS_HOST and the http://www to https://, but it still did this.

Is there anyway to modify what you wrote to make the https reflect in the browser bar at all times as well.

Regarding your 301 redirect point. How exactly does that work? Also how often does google change their index?
Was This Post Helpful? 0
  • +
  • -

#4 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 17 May 2015 - 08:56 PM

Just saw your edit. Writing it as that didn't allow the https to go through either. I tried changing the HTTP_HOST to HTTPS_HOST as well.


Where would I access this?

Make sure that apache is also enabled to do rewriting.

a2enmod rewrite



I have a host with cpanel.
Was This Post Helpful? 0
  • +
  • -

#5 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 18 May 2015 - 06:27 AM

Were you meaning to have this on?

RewriteEngine On


If so I do, but still doesn't display the https
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2225
  • View blog
  • Posts: 6,749
  • Joined: 15-January 14

Re: .htaccess rule not being followed only when coming from google

Posted 18 May 2015 - 10:06 AM

What does your .htaccess file look like now?
Was This Post Helpful? 0
  • +
  • -

#7 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 18 May 2015 - 10:49 AM

View PostArtificialSoldier, on 18 May 2015 - 10:06 AM, said:

What does your .htaccess file look like now?



I changed it back to the original I had, so the only thing in it is this..

RewriteEngine On
 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: .htaccess rule not being followed only when coming from google

Posted 18 May 2015 - 10:58 AM

View Postpfar54, on 17 May 2015 - 11:08 PM, said:

I had a .htaccess rule created for me by my hosting company.
...
Initially the created the file as https://www.example.com. This caused my issues and took me forever to figure out that was the issue to my problems. It was causing my session to end and a new one would start. It also made anyone have to try logging in twice before they were able to login.

Are your links pointing to the https or http links? Also, the session should have a relatively normal time to live, so simply clicking links shouldn't result in session timeouts.

Are you guessing that the .htaccess file is the cause of this, or do you have definitive proof?
Was This Post Helpful? 0
  • +
  • -

#9 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 18 May 2015 - 11:07 AM

View Postno2pencil, on 18 May 2015 - 10:58 AM, said:

View Postpfar54, on 17 May 2015 - 11:08 PM, said:

I had a .htaccess rule created for me by my hosting company.
...
Initially the created the file as https://www.example.com. This caused my issues and took me forever to figure out that was the issue to my problems. It was causing my session to end and a new one would start. It also made anyone have to try logging in twice before they were able to login.

Are your links pointing to the https or http links? Also, the session should have a relatively normal time to live, so simply clicking links shouldn't result in session timeouts.

Are you guessing that the .htaccess file is the cause of this, or do you have definitive proof?



Before my .htaccess file I did not have one issue with signing in. Once it was added this problem started. The problem is fixed now in that regard as I took the www. out and that fixed the session issue as well.

The only issue now is google.


Except for an issue I was having with trying to take out the .php file extensions out of the browser. It was stopping my form's from posting. So I just took that out of it for now and will deal with that later.
Was This Post Helpful? 0
  • +
  • -

#10 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 19 May 2015 - 06:16 AM

Actually I should say, the only issue now is when my site is accessed through www.
Was This Post Helpful? 0
  • +
  • -

#11 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: .htaccess rule not being followed only when coming from google

Posted 19 May 2015 - 06:22 AM

Create a redirect on non-specific protocol (80/443) for www or non-www, & then check for protocol (80) & rewrite as https.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]



Verified with Made With Love
Was This Post Helpful? 0
  • +
  • -

#12 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 19 May 2015 - 06:36 AM

That just about fixed the issue, but some of the issues I had before are still present. When coming from google and trying to sign in, it redirects to my home page again. When typing in my site as example.com the issue isn't there.

It seems like my past issue and the current one flip flipped with this.

Any idea?
Was This Post Helpful? 0
  • +
  • -

#13 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: .htaccess rule not being followed only when coming from google

Posted 19 May 2015 - 06:52 AM

'coming in from google' is incredibly vague. If I had to take a guess, you have http://www something values cached with google, & are expecting everything to sort itself out. You're either going to need to update your google webmasters tools (assuming you have one) & request for a cache clear, or try to handle it with some server side magic.

But since I don't know any of the specifics, that's the best I can venture to guess as the situation & the solution.
Was This Post Helpful? 0
  • +
  • -

#14 pfar54   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 496
  • Joined: 30-April 15

Re: .htaccess rule not being followed only when coming from google

Posted 19 May 2015 - 07:08 AM

View Postno2pencil, on 19 May 2015 - 06:52 AM, said:

'coming in from google' is incredibly vague. If I had to take a guess, you have http://www something values cached with google, & are expecting everything to sort itself out. You're either going to need to update your google webmasters tools (assuming you have one) & request for a cache clear, or try to handle it with some server side magic.

But since I don't know any of the specifics, that's the best I can venture to guess as the situation & the solution.



You're right that was vague. I changed my code back to how it was.

If I try to access my site via google or typing in the browser bar https://www.example.com . Then if I go to sign-in the page redirects to the index because of the www. If I do not access the site through google or with the www. Everything is fine.

With the code you presented me, if https://www.example.com is typed into the browser bar or if you access my site via google, as google still has my site with the www., the problem is still present and doesn't take away the www.
Was This Post Helpful? 0
  • +
  • -

#15 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: .htaccess rule not being followed only when coming from google

Posted 19 May 2015 - 07:10 AM

If you can't share your full url path here, you can trial & error with the site I provided in my code :

View Postno2pencil, on 19 May 2015 - 09:22 AM, said:

Verified with Made With Love


If I had to take a guess, you're putting your .htaccess file in location A : & it is un-effected by where Google presents a link to location B

Lastly, I will add, you should also try another browser, or incognito mode. I've had htaccess rules corrupt cache before, & was unable to clear it. Kept fighting a ghost.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2