0

i found following Rewrite Rules, i would like to combine. They are stored in the /etc/apache2/sites-enabled/000-default.conf

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

Unfortunately it is not working together, only one of them is working.

For example: If i open http://example.com/ it redirects me to https://example.com/ If i open https://www.example.com/ it redirects me to https://example.com/

So far, so good.

But if i open http://www.example.com/ ... it does nothing.

Why?

Edit:

    <If "%{HTTP_HOST} == '^www\.example\.com$'">
      RewriteRule ^(.*)$ https://example.com/$1 [NC,R=301,L]
    </If>
    <If "%{SERVER_PORT} != '^443$'">
      RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
    </If>

Also is not working.

Zero91
  • 1
  • 2
  • There is no need to "combine" those two rules. It sounds like either those two rules are in the wrong place or something else is actually triggering the redirects you are seeing. Where exactly are those rules? They would only be valid inside a `` container, but if you have access to the server config then you shouldn't be using mod_rewrite to begin with for these type of redirects. – MrWhite Jul 04 '22 at 23:19
  • Does this answer your question? [Redirect https://www to https://non-www](https://stackoverflow.com/questions/39868410/redirect-https-www-to-https-non-www) It also covers non-SSL request redirects. – Walf Jul 22 '22 at 01:08

0 Answers0