1

Thanks to the people of Stack Overflow I have the following in my htaccess to force www and https in URLs. It forks fine:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

Now - for my local enviroment - I want to exclude a URL of the form "local.name.de"

According to this post Apache mod_rewrite: force www only if not in localhost I added the following line:

RewriteEngine on
RewriteCond %{HTTP_HOST} !=local #new line
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

but it does not work. I also tried this without success:

RewriteCond %{HTTP_HOST} !=local.name.de

Could you help me on this? Thanks

Phantom
  • 638
  • 1
  • 7
  • 18
  • 1
    Add `RewriteCond %{HTTP_HOST} !^local` line, above both exiting RewriteConds – Dusan Bajic Nov 09 '17 at 09:57
  • Thank you very much. Now the www will not be added, but it still forces https. Adding the same line a second time before `RewriteCond %{HTTPS} off`does not help. – Phantom Nov 09 '17 at 11:18
  • Perhaps you have 301 redirect cached in your browser, can you try from clean browser or from command line (with `curl -v http://local.name.de` for example) – Dusan Bajic Nov 09 '17 at 11:23
  • Once again thank you very much. I just changed the order and than it works. I will post the working solution. – Phantom Nov 10 '17 at 12:53

1 Answers1

0

At the end, this works:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^local
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^local
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Phantom
  • 638
  • 1
  • 7
  • 18