Just installed a new fresh 12.04 ubuntu server.
Always used the boilerplate redirection to remove www but it looked like it did not support https so I started looking around. Tried everything I found & somehow http "www" removal works well but https won't redirect.
Here is what I use (in a bp_rewrite.conf file in /etc/apache2/conf.d) :
# Rewrite "www.example.com -> example.com"
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
</IfModule>
Has anyone experienced this?
In order for the
RewriteRule
to trigger, bothRewriteCond
directives has to be true.How about this:
Now, if just one of the conditions remain true (as for
https://www.example.com/
, where only the first condition is true), theRewriteRule
is appliedYour example code looks slightly overly complicated, but very close to what I use:
Note: This simply rips anything off the front of the domain name's last two parts. So your user could enter
what.the.example.com
and it would reduce it toexample.com
. If your domain name isexample.co.uk
or something with three parts the end of the first line would have to be modified to fit.