SOLVED Doing an htaccess redirect for www to non-www with https?

Melissa2019B

Member
Jan 29, 2019
9
1
3
Denver
cPanel Access Level
Website Owner
Please bear with me on this. I'm a small business owner and have been doing my own website, hosted at my ISP. I know almost nothing about this. But some people in a SEO forum mentioned that I have a www and non-www version of my site out there. Both are https. And apparently Google sees this as two sites, thinks it's duplicated, and downgrades it. So I need to do some code in a htaccess file. The following is some code that people suggested that I use, 2 years ago, with the redirect added, but when I add this redirect, I get a server error after that. So could you please look this over and if the code after it is causing me problems too, please help me correct it all? Thanks!
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.net [NC]
RewriteRule ^(.*)$ https://example.net" /$1 [L,R=301]

SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(?:exe|t?gz|zip|bz2|sit|rar)$ \
no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

FileETag none

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 year"
ExpiresByType text/javascript "access 1 year"
ExpiresByType application/pdf "access 1 year"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType application/x-shockwave-flash "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 year"
</IfModule>
## EXPIRES CACHING ##

<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>




<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>

<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>

<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
</IfModule>

</IfModule>

<FilesMatch "\.(css|js|htc|CSS|JS|HTC)$">
FileETag None


</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$">
FileETag None
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
FileETag None
</FilesMatch>

<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
 
Last edited by a moderator:

Tarak Nath

Well-Known Member
Mar 12, 2018
119
15
68
India
cPanel Access Level
Root Administrator
Hello @Melissa2019B ,

What I understand that the URL should be only one (forcefully from https://www to https://) like: https://your-domain.com

1. Is your site static? If yes the you can try to use below code in your htaccess file:

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
2. If the site is dynamic and using any framework (like: WordPress) with database then you might need change the URL in the database as well.
 

Anupam SG

Active Member
Aug 29, 2018
44
17
8
Earth
cPanel Access Level
Root Administrator
You can check the CMS by entering the website URL on the link below:

whatcms.org/

Once you get to know the CMS, an adequate solution can be looked for accordingly.
 
Last edited by a moderator:

Infopro

Well-Known Member
May 20, 2003
17,075
524
613
Pennsylvania
cPanel Access Level
Root Administrator
Twitter
indicates they are using Responsive Site Designer 1.5.1419
They have their own support forums worth checking out I suppose:
coffeecup.com/forums/responsive-site-designer/the-cpanels-autossl-certificate/

That should help with the redirects. As for the rest of your original posts htaccess stuff, you could try adding one section at a time and see which one is breaking the site.

IMHO, you should probably give up on coffeecup software for a website builder and move to something more modern. Checking your website, it's quite dated and not responsive at all.
 
  • Like
Reactions: Tarak Nath

Melissa2019B

Member
Jan 29, 2019
9
1
3
Denver
cPanel Access Level
Website Owner
A nice guy with my ISP took some mercy on me, and corrected the redirect and uploaded the .htaccess. He asked that I please not mess with it myself anymore, and I agree. :) But it works now. If you enter with www it instantly redirects do example.com

Thanks people!
 
Last edited by a moderator:
  • Like
Reactions: Infopro