.htaccess file not working

I uploaded .htaccess file in htdocs directory but htaccess does not work
htaccess is:

# Canonical https/www (when using proxy)
<IfModule mod_rewrite.c>
	RewriteCond %{HTTP:X-Forwarded-Proto} !https
	RewriteCond %{HTTPS} off
	RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
	
	RewriteCond %{HTTP_HOST} !^www\. [NC]
	RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Replace that with your domain. Yup, sometimes that won’t work

1 Like

I tried that, but it still doesn’t work

If that is a part of your .htaccess, then you must note that all separate rules must be on their own individual lines, which from this bit of code, you have two rules on the same line.

Your code should be more like this:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
1 Like

So what does it do? It’s not doing what you expect it to, I get that, but not what the result of this code is.