If this is your first visit, check our documentation. To post, register or login.
Forums / Search Engines / 301 redirects in .htaccess and server at host - a problem or not?

301 redirects in .htaccess and server at host - a problem or not?

Started by shags38 on 11 Sep 2017, 7:15 AM · Views: 69

Results 1 to 4 of 4
11 Sep 2017, 7:15 AM
#1
shags38 avatar

shags38

Totally Zenned

Join Date:
Jan 2011
Location:
Adelaide, Australia
Posts:
1,684
Plugin Contributions:
0

301 redirects in .htaccess and server at host - a problem or not?

Is having a server side redirect http:// domain> https ://domain (with & without ww w.), and having the same 301 redirect rewrite in a .htaccess file in the root, creating two redirects and as such an issue or do the crawlers not take any notice of .htaccess 301 redirect because of server side redirect?

If it is creating two redirects is it best just to leave it as the server side redirect and eliminate it from the .htaccess in the root? The .htaccess file is there for USU friendly urls rewrite and the http:// domain > https:// domain 301 rewrite is at the bottom of the file, i.e. url rewrites are listed first.

cheers,
Mike

11 Sep 2017, 8:10 AM
#2
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: 301 redirects in .htaccess and server at host - a problem or not?

looking at a .htaccess of one of my customers i see this, and it seems to work fine (although I am in no way an expert on this).

RewriteEngine On


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


RewriteCond %{HTTP_HOST} ^DOMAIN\.COM [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://DOMAIN.COM/$1 [R,L]

Where DOMAIN.COM needs to be replaced with your domain name

11 Sep 2017, 4:43 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 301 redirects in .htaccess and server at host - a problem or not?

Perhaps backwards in description of the process, but it is intended to provide understanding more than just give a direction.

First the content of the htaccess is not made known to any visitor of the site, so you could have the same operation listed 100s of times in the htaccess file and no visitior whether SE or person would know what was in there or that the same thing was duplicated 100s of times. Yes there would be a performance impact by the size of the file, but that's different.

Then, there is the redirects themselves, generally speaking the more times one needs to bounce around the more suspicious the activity appears and the longer it takes to get to the destination. Reportedly also if it takes more leaps to get to the destination then presumably it will have a negative affect on rankings.

Then there is the sequence of redirects. For example, the above sample of redirects will first evaluate if the uri has www. on the front of the uri and if so, will redirect to the http: version of the site without the www. prefix. Then if that initial uri had been entered without https: it would redirect by the second rule to the https: version of the uri. So, entering https://www.mydomain.com would result in two redirects occurring. Unfortunately, the same would be true if https://www.mydomain.com was entered. (www. found, redirect to http://mydomain.com and then redirect to https://mydomain.com). If the first rule were written to also redirect to https: then in the case where someone entered: https://www.mydomain.com, there would only be one redirect rather than two because of the www. prefix. I personally opt to put both conditions in a single evaluation so that there is always just one hop from a http: entry either with or without www. as desired for the site. (ie. Having or not having www. as a prefix is primarily a personal decision now-a-days.)

As to the placement of rules within the file, generally speaking such rewrites are top down. Placing the https: and/or www. related rewrites after a rewrite that could stop any further evaluation if the conditions are true to execute the rule, would prevent those rules from being executed and therefore serve no direct purpose.

In your situation, you asked about a server side rewrite, that is expected to occur before rewrites within the htaccess file. Therefore, if you have a server side redirect that does what your htaccess does, then the htaccess has unnecessary commands in it. Further, since those are expected to address aspects of the uri unrelated to the uri rewriter, they should be ahead of the uri rewriter code (which I thought was covered in notes of the htaccess file content from the rewriter.)

So sum and total in your case: use the server side redirect, do not add the same redirect to the .htaccess file and decide on what you want, to always have www. or to never have it. If you don't choose one, then let the search engines know that by going to either they are reaching the same page so that indexing is more accurate, but it is better to control it up front rather than trying to reach out to any/all services that need to know about that minor aspect.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

14 Sep 2017, 9:44 AM
#4
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: 301 redirects in .htaccess and server at host - a problem or not?

shags38:

Is having a server side redirect http:// domain> https ://domain (with & without ww w.), and having the same 301 redirect rewrite in a .htaccess file in the root, creating two redirects and as such an issue or do the crawlers not take any notice of .htaccess 301 redirect because of server side redirect?

If it is creating two redirects is it best just to leave it as the server side redirect and eliminate it from the .htaccess in the root? The .htaccess file is there for USU friendly urls rewrite and the http:// domain > https:// domain 301 rewrite is at the bottom of the file, i.e. url rewrites are listed first.

cheers,
Mike

If by "server side redirect" you mean the server Apache config file, that file takes precedence over an .htaccess file so having the same Redirect in both is an unnecessary redundancy.

The learning is in the doing.

Potent Products