Steve Peterson

Registered
Sep 25, 2018
1
0
1
USA
cPanel Access Level
Website Owner
Thank you in advance. Here is my question:

I placed the following 2 lines of code in my .htaccess file to redirect non-WWW to WWW:
Code:
RewriteCond %{http_host} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Last year, cPanel was upgraded on my server and it now "adds its own code" to my .htaccess file. Here is what is looks like now:
Code:
RewriteEngine On
RewriteCond %{http_host} ^example.com [nc]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
Question 1.)
It looks like cPanel only put rewrite 'Conditions'... where is its rewrite 'Rule' ??

Question 2.)
Their code interspersed with my code... wouldn't it be better if I pulled out my code and placed it at the beginning, so the end result looks like this?
Code:
RewriteEngine On
RewriteCond %{http_host} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
Question 3.)
If I change around the code, do I have to do this every month when cPanel 'refreshes' and/or adds new code?

Question 4.)
I'm a 'newbie' when it comes to Rewrites... what your your thoughts regarding my questions -- any further suggestions, or questions I failed to ask?

Thank you again!
 
Last edited by a moderator:

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,304
1,252
313
Houston
Hi @Steve Peterson

The rewrite conditions are added to include an exception for cPanel's AutoSSL. These will not be readded every year they will be re-added every 90 days when AutoSSL runs. There is no issue with leaving them as is, we've gone to great lengths to ensure that the exceptions don't interfere with the functionality of the rewrite rules. From my own personal perspective, I believe it's best to leave them alone.

Thanks!