RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com$1 [R,L]
I added RewriteLog and set the level to 9 so that everything was logged for the port 443 entry, but the log is not updated. To reiterate, the problem is forcing https://domain.com to https://www.domain.com. I can't force www and then http to https when https is being initially connected to.
🔒 Locked
🤖 Godot
[web] Using mod_rewrite in https, not mod_rewrite to https
Advertisement
Original Post
I've got a domain that I'm forcing www and https on. When accessing domain.com, everything is rewriting perfectly. However, the issue I'm having is to force https://domain.com To rewrite to https://www.domain.com The settings currently in place:
Either I'm not making my problem clear or people are glancing over what I'm describing as the problem since this is the third time a solution for port 80 was suggested when the problem is located on port 443. While the redirect can help me reduce the rewrite rules I have to force www and https (I intend on using it, thanks), I need the site to go to https://www.domain.com when https://domain.com is accessed.
Quote:
Well there's nothing to post when using the rewrite I have in place.
Eh? That can't be. With RewriteLogLevel set to 9 it should take Apache well over 100 lines per request to not match a simple rule. When the Apapche guys warn you about RewriteLogLevel 3 and up being verbose enough to kill your server in a live environment, they are not kidding.
Are you sure you are looking at the file set by RewriteLog, and not the standard Apache access log or error log?
Yep, I'm positive the file is correct.
The following SSL config does not update the rewrite log:
The following does:
The only difference is the :443 on the end. Realistically, you can be anything on the end and it would yield the same results (a friend suggested trying it with 443 since the problem lies in the SSL config, not the port 80 config). Here's another baffling event of logging, or lack thereof. My original configuration would not cause the log to update (even with the level at 9). My port 80 configuration, which did not have the log enabled, was updating the rewrite log. The following may be off in a spot or two because I'm going by memory since this configuration is no longer in place (Port 80 connections automatically redirect to 443 instead of using mod_rewrite). This is the gist of what I had:
My assumption would be that the rewrite log would only update when rewriting occurred on port 443 since that is the only configuration that says to use it, but hey, I've been wrong before!
The following SSL config does not update the rewrite log:
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]RewriteRule ^(.*)$ https://www.domain.com$1 [R,L]The following does:
RewriteCond %{HTTP_HOST} !^www.domain.com:443$ [NC]RewriteRule ^(.*)$ https://www.domain.com$1 [R,L]The only difference is the :443 on the end. Realistically, you can be anything on the end and it would yield the same results (a friend suggested trying it with 443 since the problem lies in the SSL config, not the port 80 config). Here's another baffling event of logging, or lack thereof. My original configuration would not cause the log to update (even with the level at 9). My port 80 configuration, which did not have the log enabled, was updating the rewrite log. The following may be off in a spot or two because I'm going by memory since this configuration is no longer in place (Port 80 connections automatically redirect to 443 instead of using mod_rewrite). This is the gist of what I had:
<VirtualHost *:80> ServerAdmin webmaster@domain.com DocumentRoot /path/to/domain.com ServerName domain.com ServerAlias *.domain.com RewriteEngine on RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RewriteRule ^(.*)$ https://www.domain.com$1 [R,L] RewriteCond %{HTTPS} off RewriteRule ^(.*) https://%{HTTP_HOST} [R,L]</VirtualHost><VirtualHost 67.192.103.223:443 192.168.100.223:443> ServerAdmin webmaster@domain.com DocumentRoot /path/to/domain.com ServerName domain.com ServerAlias *.domain.com LogLevel warn RewriteEngine on RewriteLog /var/log/httpd/domain.com_rewrite_log RewriteLogLevel 9 RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RewriteRule ^(.*) https://www.domain.com$1 [R,L]</VirtualHost>My assumption would be that the rewrite log would only update when rewriting occurred on port 443 since that is the only configuration that says to use it, but hey, I've been wrong before!
Quote:
Realistically, you can be anything on the end and it would yield the same results
Interesting. Perhaps modify your condition to:
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]The difference is that I dropped the $ at the end. $ matches the end of a string, so you end up matching the whole HTTP_HOST. With this modified condition you only match the start.
It was worth a shot, but still no dice. Log also does not update when trying it without $ on the end. The log does update when accessing the proper URL. Here's what was listed in case it reveals anything:
[18/Jul/2008:14:58:45 --0500] [www.domain.com/sid#85bc170][rid#8d36ee8/initial] (2) init rewrite engine with requested uri /index.php[18/Jul/2008:14:58:45 --0500] [www.domain.com/sid#85bc170][rid#8d36ee8/initial] (3) applying pattern '^(.*)' to uri '/index.php'[18/Jul/2008:14:58:45 --0500] [www.domain.com/sid#85bc170][rid#8d36ee8/initial] (4) RewriteCond: input='www.domain.com' pattern='!^www.domain.com' => not-matched[18/Jul/2008:14:58:45 --0500] [www.domain.com/sid#85bc170][rid#8d36ee8/initial] (1) pass through /index.php
Three things you can try:
1) Enable rewrite logging on port 80 as well and log to a different logfile. See if your https request is accidentally picked up by the other host (unlikely, but worth a shot).
2) modify your condition rule to:
RewriteCond %{HTTP_HOST} ^.*www [NC]
Perhaps there is something in front of the www when on https. Again, unlikely but worth a shot.
3) Apache does not support name-based virtual hosting on https (there is a way around that). So, all your requests on port 443 always end up in the same virtual host config. Make sure that your host is the *only* host on port 443 for these IP addresses. Make sure that there is no "default" host in your configuration anywhere in the standard Apache configuration.
1) Enable rewrite logging on port 80 as well and log to a different logfile. See if your https request is accidentally picked up by the other host (unlikely, but worth a shot).
2) modify your condition rule to:
RewriteCond %{HTTP_HOST} ^.*www [NC]
Perhaps there is something in front of the www when on https. Again, unlikely but worth a shot.
3) Apache does not support name-based virtual hosting on https (there is a way around that). So, all your requests on port 443 always end up in the same virtual host config. Make sure that your
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement