-1

I currently have my rewrite rules in the post_virtualhost_2.conf file this in inserted into the httpd.conf file at the absolute end.

I have two blocks that don't seem to be working

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{HTTPS} !=on
   RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule> 
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{SERVER_ADDR} !=127.0.0.1
    RewriteCond %{SERVER_ADDR} !=::1
    RewriteRule ^ %{ENV:PROTO}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

The full conf is here

What I am expecting is the following in all cases

But when I enter privatmamtora.com it simply get a 200 response.

PS. I am hoping that the rules could be subdomain safe. (Not break subdomains)

EDIT

Rewrite module is loaded.

1 Answers1

0

You don't mention which OS this is working with, so I'll keep it generic.

It's possible that the mod_rewrite module isn't enabled and so the config is ignored due to the <ifModule mod_rewrite.c>

You need to confirm that this module is actually loaded.

Also you don't need two sets of <IfModule ...>

This currently works for me:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^WWW\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Joshua Griffiths
  • 2,164
  • 14
  • 19