Setup Permanent 301 Redirects after moving to Https [closed]

RewriteCond %{HTTP_HOST} ^xxxz.com.qa [NC,OR]
RewriteCond %{HTTP_HOST} ^www.xxxz.com.qa [NC]
RewriteRule ^(.*)$ https://www.xxxz.com.qa/$1 [L,R=301,NC]

This will result in a redirect loop as it will repeatedly redirect https://www.xxxz.com.qa/<url> to https://www.xxxz.com.qa/<url> again and again…

If you want to redirect from HTTP then you need to check that the request was for HTTP before redirecting to HTTPS. For example:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

No need for the NC flag, as you are simply matching everything anyway.


However, this conflicts with the existing directives at the end of your file:

RewriteCond %{HTTP_HOST} ^xxxz\.qa$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xxxz\.qa$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]    {32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/xxxz\.com\.qa" [R=301,L]

These directives should probably be deleted. (Fortunately, they probably aren’t doing anything anyway – because they are after the WordPress front-controller.)