Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Aug 16, 2014 9:28 pm 
Offline
Senior Member

Joined: Thu Apr 12, 2012 6:45 am
Posts: 60
Website: http://anderssonweb.se
Location: Puerto Galera, Philippines
Hi,

Have a strange problem. Using certificate for a few domains, but one of them has an issue with the Apache configuration.

This is the apache configuration for the virtual host:
Code:
<VirtualHost *:80>
  ServerAdmin support@domain.tld
  ServerName www.domain.tld
  ServerAlias domain.tld

  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^$ [OR]
  RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
  ServerAdmin support@domain.tld
  ServerName www.domain.tld
  ServerAlias domain.tld

  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^ https://www.domain.tld%{REQUEST_URI} [R=301,L]

  DocumentRoot /var/www/domain.tld/public_html/
  ErrorLog /var/www/domain.tld/logs/error.log
  CustomLog /var/www/domain.tld/logs/access.log combined

  SSLEngine on
  SSLCertificateChainFile /etc/ssl/AlphaSSLRoot-Bundle.crt
  SSLCertificateFile /etc/ssl/localcerts/www.domain.tld.crt
  SSLCertificateKeyFile /etc/ssl/localcerts/www.domain.tld.key
</VirtualHost>


http://domain.tld redirects OK to https://www.domain.tld
http://www.domain.tld redirects OK to https://www.domain.tld

But https://domain.tld does not work at all, just getting "Server not found". It should of course redirect to https://www.domain.tld. Since http://domain.tld redirects okay above, it shouldn't be a DNS issue, but something in the Apache config.

Any help on this is appreciated! Thanks!


Top
   
PostPosted: Mon Aug 18, 2014 7:36 am 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
Could it be that you don't have this line in your https section even though it's in your http section?
RewriteCond %{HTTP_HOST} !^$ [OR]

I'm no htaccess expert, but I've always used that line as part of the conditions when forcing 'www'.


Top
   
PostPosted: Tue Aug 19, 2014 2:57 am 
Offline
Senior Member

Joined: Thu Apr 12, 2012 6:45 am
Posts: 60
Website: http://anderssonweb.se
Location: Puerto Galera, Philippines
Hi,

What exactly is that row doing? I tried to put it first (after RewriteEngine on) but then I'm getting "Page is redirecting the wrong way" and it stops loading. Any other suggestions?


Top
   
PostPosted: Tue Aug 19, 2014 4:40 pm 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
Webkungen,
I'm not sure what it does, but I've always needed it for redirecting to 'www'.

James


Top
   
PostPosted: Tue Aug 19, 2014 4:49 pm 
Offline
Senior Newbie
User avatar

Joined: Thu Oct 23, 2008 9:25 pm
Posts: 16
Website: http://bofh.hosscomm.com
The best reference I know of for .htaccess redirects is http://www.askapache.com/category/htaccess/
I have had considerable good fortune following visits to that site. There is considerable quality information there regarding all of apache. Hope that site is found to be useful. 8)

about 1/2 way down that page is this http://www.askapache.com/category/htaccess/mod_rewrite.html
(added that specific link)


Top
   
PostPosted: Tue Aug 19, 2014 8:50 pm 
Offline
Senior Member

Joined: Thu Apr 12, 2012 6:45 am
Posts: 60
Website: http://anderssonweb.se
Location: Puerto Galera, Philippines
Hi,

Thanks for the link, but cannot find what I'm looking for. The force www is working fine for the Non-SSL (port 80) part, the problem is that https:// won't redirect as it should.


Top
   
PostPosted: Tue Aug 19, 2014 9:19 pm 
Offline
Senior Newbie
User avatar

Joined: Thu Oct 23, 2008 9:25 pm
Posts: 16
Website: http://bofh.hosscomm.com
this is a working example... for doing it the 'other way'... forcing https and no 'www'.
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
#Second Force HTTPS via redirect/rewrite
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


I think if you use mine as a template you will get working as you desire.... as yours stands apache has no way to know that 'https://domain.tld' exists... it seems to be refering it back into a loop so it tells you it failed.
take note of the ".*"[dot*]

try this code for your line that looks similiar:(the last line)
Code:
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group