DouglasRedvers

Registered
Nov 27, 2018
2
0
1
Australia
cPanel Access Level
Website Owner
Hi there,
I have the below code in my htaccess to direct to https.
Recently I have needed to add more code to make sure my site redirects from index.php to just the domain as otherwise I get a duplicate page at mysite.com.au and mysite.com.au/index.php

I have been trying to find an efficient method of doing this as well as 301 redirecting to https.
The code posted below redirects the index fine and also non-www but if http is inputted it does not go to https. Can anyone see what is wrong


Code:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ https://www.domain.com.au/ [R=301,L]

RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteCond  %{HTTP_HOST}  !^www\.  [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule  ^(.*)$  https://www.domain.com.au/$1 [R=301,L]
 
Last edited by a moderator:

DouglasRedvers

Registered
Nov 27, 2018
2
0
1
Australia
cPanel Access Level
Website Owner
I have solved it with help of a few others. The below now works as it should.

I would like to know if it is possible to remove the

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$

references or are they necessary for the ssl





Code:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ https://www.site.com.au/ [R=301,L]

RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule  ^(.*)$ https://www.site.com.au/$1 [R=301,L]

RewriteCond %{HTTP_HOST}  !^www\. [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule  ^(.*)$ https://www.site.com.au/$1 [R=301,L]
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hi @Douglas Machado


I'm glad to hear you were able to solve your issue. Thanks for updating and letting us know and for providing the solution that worked for you.
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Hello @David Colter


This is added to the .htaccess file when something prevents the DCV check from completing successfully. It's necessary for AutoSSL to function and while you can remove it, it will be readded during the next AutoSSL run. This is an exception rule that only allows the cpaneldcv check to successfully complete and should not interfere with anything else.