Avatar of Mike Paradis
Mike Paradis

asked on 

Web site: http forwards to https causing 301 errors - SEO issue?

We have a web service which is https only. The web server allows port http connections but forwards them to https since there are no http urls in the database for the site.

I've noticed in the logs that when connections are made to http, they are getting a 301 and being redirected to https.
Is this a problem in terms of configuration and in terms of SEO?
Search Engine Optimization (SEO)Apache Web ServerWeb Servers

Avatar of undefined
Last Comment
gheist
Avatar of Dr. Klahn
Dr. Klahn

As far as search engines go, this is probably preferable to rewriting the URL on the sly and redirecting without notifying the client.

Status code 301 tells the client "This resource has moved permanently, please don't use this outdated link any more; I'm redirecting you to the new one."  Search engines should notice this and change their stored links from http:// to https://

Eventually the http:// traffic should die off except for (a) outdated direct links on web pages and (b) people who type in the web site name manually.
Avatar of gheist
gheist
Flag of Belgium image

Bing and google agree that 301 is the best way to redirect URLs
Avatar of Mike Paradis
Mike Paradis

ASKER

But no 301 is configured, it's just happening because there aren't any http urls on the site.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Something must be configured or you would be getting 404's.
Avatar of Dr. Klahn
Dr. Klahn

I agree with Dave.  http:// does not redirect or "fail over" to https:// automatically.

If HTTP redirected to HTTPS by default, every site would need SSL certificates.
Avatar of gheist
gheist
Flag of Belgium image

I think your monitoring system misinterprets 3xx HTTP return codes as 'errors'
You need to enable following that 301 redirect status code.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

That's right, 301 status code is not an error.  Here are the HTTP status codes and what they mean: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes   Note that Microsoft has added a bunch of subcodes of their own.
Avatar of Mike Paradis
Mike Paradis

ASKER

There is no 301 configured. The server simply accepts http connections but the site only has https urls.

Watching the logs, I think I am seeing that those 301's are not being redirected after all. I see them die in http and then do not seem them in the https logging.

I think this means that this has been lost traffic and not a redirect.
However, I guess the simple fix is to actually put a 301 into the http host directives.

Something like;

<VirtualHost *:80>
        ServerAdmin support@example.com
        DocumentRoot /var/www/html
        ServerName www.example.com
        ServerAlias example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</VirtualHost>

There is already a 443 section for the https configuration of course.
The config has been updated and I can see port 80 connections getting a 301 with a redirect to port 443.

I've read that this needs to be very carefully done otherwise some browsers, especially IE (of course) don't follow the redirect.
Avatar of gheist
gheist
Flag of Belgium image

What is that R=301? Maybe read manuals while copying and pasting config files from websites?
Avatar of Mike Paradis
Mike Paradis

ASKER

@gheist - I found it on the net, and tested it first and it seems to work.

The 301 is the permanent redirect and the L means;

From official doc

The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. This corresponds to the last command in Perl, or the break command in C. Use this flag to indicate that the current rule should be applied immediately without considering further rules.

If you know something I don't since I'm not an expert at redirection, hence why I posted my question on this site, then please feel free to share.
Avatar of gheist
gheist
Flag of Belgium image

You knowingly put redirect with code 301, than wonder why code 301 appears in server responses?

More elegant way to do same as the rewrite system is:

Redirect perm / https://your.site.com/
Avatar of Mike Paradis
Mike Paradis

ASKER

@gheist You might want to re-read the entire thread. There was no 301 when I started. I've only added it after starting this post thanks to input from members.

I do use redirects where a web site is shut down and needs to be temporarily or permanently redirected. This is a simple one line directive. My question is asking about the proper way to redirect all http to https connections without messing up SEO.

So, is it as simple as

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://example.com/
</VirtualHost>

And if so, is there an SEO cost for doing this.
Also, how do I deal with ServerAlias of only example.com?

Not only do I want the least amount of directives that will cost in terms of performance but I don't want to lose SEO by doing it the wrong way.
Avatar of Mike Paradis
Mike Paradis

ASKER

I guess I'll go post this on another site. No one seems to know or be able to confirm the correct directives.
Avatar of gheist
gheist
Flag of Belgium image

Authoritative info site is Read-only:
https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect
What you were trying is default 302 temp redirect, which does not give you google SEO bonus.
As with all variable-number-of-arguments apache directives - do not put comment in same line.
Avatar of Mike Paradis
Mike Paradis

ASKER

Sorry, I am not following your input. What comment in the directives? I have only posted examples asking for confirmation or that someone simply create the actual directives I need and post this as the answer.
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Mike Paradis
Mike Paradis

ASKER

So the solution is not as complicated as the three rules I was trying.
To confirm, it is as simple as the following;

<VirtualHost *:80>
        DocumentRoot /var/www/virtualhosts/example.com/html
        ServerName www.example.com
        ServerAlias example.com
        Redirect perm / https://www.example.com/
#    RewriteEngine On
#    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
#    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</VirtualHost>

I use the Redirect method on many configurations but didn't know it could be used to redirect http to https. I've only ever used it to redirect to another domain. I also didn't know about the 'perm' option which is nice to know.
Avatar of gheist
gheist
Flag of Belgium image

Next - check your https site with qualys ssl scan, make it A+ or better, that way you learn your ways around (new) mod_ssl

I know it is not your fault :) Rewrite rules look so weirdly unreadable that people avoid understanding them...
Avatar of Mike Paradis
Mike Paradis

ASKER

Using the above config, the apache service will not restart.

# apachectl -t
AH00526: Syntax error on line 86 of /etc/httpd/conf/httpd.conf:
Redirect: invalid first argument (of three)

The config is;

<VirtualHost *:80>
        DocumentRoot /var/www/virtualhosts/example.com/html
        ServerName www.example.com
        ServerAlias example.com
        Redirect perm / https://www.example.com/
</VirtualHost>
Avatar of gheist
gheist
Flag of Belgium image

Redirect permanent / https://.../

# apachectl configtest
All OK
Avatar of Mike Paradis
Mike Paradis

ASKER

Interesting that looking on the net, there are also mentions of using the wrong term, 'perm'.

Thanks. The service restarted with the simpler redirect. I'll watch it a little to make sure I see connections moving from http to https then this question should be complete.
Avatar of Mike Paradis
Mike Paradis

ASKER

Seems to be working.
I can see IPs hitting http then being redirected to https in the logs.

The only part that is odd to me is that this is now a 301, specified yet, I watched one IP get redirected from http to https, then minutes later, I saw it to the same thing. Should their browser not have noticed the permanent redirect?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Nothing about this stops the user from clicking on the same old 'http' link whenever they want.  You'll still see that every time they do that.
Avatar of gheist
gheist
Flag of Belgium image

perm was alias for permanent in apache 2.0 :)
Avatar of Mike Paradis
Mike Paradis

ASKER

While I'd like to thanks others for their input, the actual solution was from gheist.

In the end, when I try to find information for apache configurations, I usually add the version I am using, in this case, 2.4. I failed to do that when searching for solutions and found myself trying old style methods. Seems to be working perfectly now.

Thanks again for the help.
Avatar of gheist
gheist
Flag of Belgium image

Start with apache httpd documents. Internet remembers everything since inception of apache httpd and you usually hit docs that do not anchor to any apache version number.
Web Servers
Web Servers

A web server refers to the software that helps to deliver web content that can be accessed either through the Internet or through an intranet. The primary function of a web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). The most common use of web servers is to host websites, but there are other uses such as gaming, data storage, running enterprise applications, handling email, FTP, etc.

33K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo