htaccess redirect from www to https issue
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
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]-
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 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]0 -
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. 0 -
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
@cPanelLauren Is there an answer to this question? Is this addressed in another thread?0 -
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. 0
Please sign in to leave a comment.
Comments
4 comments