Forum Moderators: phranque

Message Too Old, No Replies

redirect from http to https pages 404

can't seem to get https redirect in .htaccess right

         

servaris

7:21 pm on May 24, 2010 (gmt 0)

10+ Year Member



Hi,

We have a quote system that up until now, used http for everything. The goal is to have the site user redirected to https for any URL that includes /quote.

The URL that anyone wanting a quote is www.domain.com/quote/system/some_number i.e. www.domain.com/quote/system/142. The .htaccess in /quote contains the following code for http:

ErrorDocument 503 /quote_maintenance.html

# uncomment this line when down for maintenance
# and perhaps you want to edit /quote_maintenance.html to indicate
# when the site will be back online.
#RedirectMatch 503 ^/.*

RewriteEngine on

RewriteCond %{HTTP:Authorization} username=\"([^\"]+)\"
RewriteCond %1 !=logout
RewriteRule system/([0-9]+) system_quote?login=%1&system_id=$1 [last,qsappend]

RewriteCond %{HTTP:Authorization} username=\"([^\"]+)\"
RewriteCond %1 !=logout
RewriteRule ^system$ system_quote?login=%1 [last,qsappend]

RewriteRule system/([0-9]+) system_quote?system_id=$1 [last,qsappend]
RewriteRule ^system$ system_quote [last]


I tried to add the following at the top directly under RewriteEngine on (I subsequently added Options +FollowSymLinks but it did not help):

RewriteCond %{SERVER_PORT} 80
RewriteRule ^system/([0-9]+)$ [w2.domain.com...] [last,qsappend]

When the above is added, the URL shows up right in the address bar on the web browser but displays

Not Found

The requested URL /quote/system/156 was not found on this server
.

Your help is greatly appreciated.

Thank you in advance.

fruitwerks

3:12 am on May 25, 2010 (gmt 0)

10+ Year Member



What do the logs say?
And if that is the right URL - you wouldn't be here :)

jdMorgan

3:46 am on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tell us a bit about your SSL certificate and how SSL requests are 'mapped' into your server filespace. On some servers, the http and https requests are handled by completely separate virtual hosts, and on others, both http and https requests are mapped into the same filespace.

If the protocol and domain in the address bar are correct in addition to the URL-path you showed above, then the problem is elsewhere -- in a higher-level .htaccess or server config file. Or maybe your DNS isn't set up right. Do you/did you use a "Control Panel" for part of the set-up? If so, what settings did you configure? Please fill in these details.

Jim

servaris

5:19 am on May 25, 2010 (gmt 0)

10+ Year Member



Hi and thank you for replying,

I went to a product page and clicked on configure, which in this case takes it to /quote/system/155. The http error log states:

File does not exist: /usr/local/www/data/domain.com/quote/system/155 and that is true. There is no file called 155. And that has to do with our original coder who coded changing an URL from something like '/?system=155' to just plain /system/155. The products called by apache have their stuff in postgresql database.

We don't use a 'control panel'. Our servers run FreeBSD. Apache22.
We use a configuration file in /usr/local/etc/apache22/Includes/domain.conf and we use /usr/local/etc/apache22/extra/http-ssl.conf (just started this to attempt to get ssl working for quotes).

You'll notice a big difference in the code between http and https. I an not sure if I should have just copied the code from http configuration into the SSL conf file and added the SSL code. Perhaps that might be our problem?

Below is the configuration of /usr/local/etc/apache22/extra/httpd-ssl.conf:

<VirtualHost x.x.x.x:443>
ServerAdmin webmaster@domain.com
ServerName w2.domain.com
DocumentRoot /usr/local/www/data/domain.com/
CustomLog /var/log/www/www.domain.com-access_log combined
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/etc/apache22/certs/domain.com/w2/server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/certs/domain.com/w2/server.key
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>
<Directory "/usr/local/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
</VirtualHost>

Below is http conf for this domain (non ssl) which works as it should

<VirtualHost x.x.x.x:80>
ServerAdmin WebMaster@domain.com
ServerName w2.domain.com
# ServerAlias domain.com
ScriptAlias /quote/ /usr/local/www/data/domain.com/quote/
ScriptAlias /check/ /usr/local/www/data/domain.com/check/
ScriptAlias /client/ /usr/local/www/data/domain.com/client/
DocumentRoot /usr/local/www/data/domain.com/

<Directory /usr/local/www/data/domain.com>
BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=On
Options FollowSymlinks Includes ExecCGI
AllowOverride All
AddHandler cgi-script .cgi
ExpiresActive On
ExpiresByType text/css "now plus 1 hour"
ExpiresByType application/javascript "now plus 1 hour"
ExpiresByType image/jpeg "now plus 1 week"
ExpiresByType image/gif "now plus 1 week"
ExpiresByType image/x-icon "now plus 1 week"
Order Allow,Deny
Allow from all

# compress
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/js
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

# Customer login functionality
AuthType Digest
AuthName "domain"
AuthDigestDomain /
AuthDigestProvider dbd
AuthDBDUserRealmQuery "select md5(email || ':domain:' || password) from client where email = %s and 'domain' = %s"

# below is the REST based HTTP authentication stuff
Include /usr/local/www/data/domain.com/quote/optional-login.conf

</Directory>

ErrorDocument 403 /error403/404.shtml
ErrorDocument 404 /error403/404.shtml
CustomLog /var/log/www/www.domain.com-access_log combined

RewriteEngine on

RewriteMap timestamps prg:/usr/local/www/data/domain.com/quote/timestamps.pl
RewriteMap optional-forced-logout prg:/usr/local/www/data/domain.com/quote/optional-forced-logout.pl

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.php$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/html$
LogFormat "%h %l %u %t \"%V %r\" %<s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n -< Out:%{mod_gzip_output_size}n = %{mod_gzip_compression_ratio}n pct." common_with_mod_gzip_info2
CustomLog /var/log/www/mod_gzip.log common_with_mod_gzip_info2
mod_gzip_dechunk Yes
</IfModule>
</VirtualHost>

jdMorgan

2:30 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to copy the ScriptAlias directives that apply to SSL requests from the non-SSL to the SSL section in your config file. This will "connect" the extensionless URLs like [example.com...] to the script that is defined as the DirectoryIndex page in the /usr/local/www/data/domain.com/quote/ directory.

This may not be --indeed, is not likely to be-- all that is required, but you will need to copy *some* of the directives from the non-SSL to the SSL section in your config file.

Jim

servaris

9:21 pm on May 25, 2010 (gmt 0)

10+ Year Member



Hi jdMorgan,
Thank you for your help. I've copied contents of http <VirtualHost> to httpd-ssl.conf and added the SSL statements. Now the works when click on a configure button -> https.

Problem now is I cannot login. The database is identical on this test server to that of the production server. I have (so I think) same setup for postgresql on this test server as the production server. The error log states:
[Tue May 25 16:29:30 2010] [error] (20014)Internal error: DBD: failed to prepare SQL statements:
[Tue May 25 16:29:30 2010] [error] (20014)Internal error: DBD: failed to initialise
[Tue May 25 16:29:30 2010] [error] [client x.x.x.x] Failed to acquire database connection to look up user 'username@domain.com:Name', referer: [w2.domain.com...]

Thanks in advance!

jdMorgan

10:10 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I've copied contents of http <VirtualHost> to httpd-ssl.conf and added the SSL statements.

To be clear, did you copy *all* of that config container, or just the ScriptAlias directives as I recommended?

JIm

servaris

2:47 am on May 26, 2010 (gmt 0)

10+ Year Member



Hi JIm,

I copied it all. I take it from your comment, remove it and just add the ScriptAlias. I will try that right now.

After removing everything except ScriptAlias statements, got 400 error. Tried a few combinations but most produce basically the same error. With the following <VirtualHost> config still can't get login to work:


<VirtualHost 69.90.68.25:443>
ServerAdmin WebMaster@domain.com
ServerName w2.domain.com
ScriptAlias /quote/ /usr/local/www/data/domain.com/quote/
ScriptAlias /check/ /usr/local/www/data/domain.com/check/
ScriptAlias /client/ /usr/local/www/data/domain.com/client/
DocumentRoot /usr/local/www/data/domain.com/
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/etc/apache22/certs/domain.com/w2/server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/certs/domain.com/w2/server.key
# <Files ~ "\.(cgi|shtml|phtml|php3?)$">
# SSLOptions +StdEnvVars
# </Files>
# <Directory "/usr/local/www/cgi-bin">
# SSLOptions +StdEnvVars
# </Directory>
# SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

<Directory /usr/local/www/data/domain.com>
BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=On
Options FollowSymlinks Includes ExecCGI
AllowOverride All
AddHandler cgi-script .cgi
ExpiresActive On
ExpiresByType text/css "now plus 1 hour"
ExpiresByType application/javascript "now plus 1 hour"
ExpiresByType image/jpeg "now plus 1 week"
ExpiresByType image/gif "now plus 1 week"
ExpiresByType image/x-icon "now plus 1 week"
Order Allow,Deny
Allow from all

# compress
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/js
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

# Customer login functionality
AuthType Digest
AuthName "Domain"
AuthDigestDomain /
AuthDigestProvider dbd
AuthDBDUserRealmQuery "select md5(email || ':Domain:' || password) from client where email = %s and 'Domain' = %s"
# below is the REST based HTTP authentication stuff
Include /usr/local/www/data/domain.com/quote/optional-login.conf

</Directory>
</VirtualHost>

ErrorLog shows:

[Tue May 25 22:41:19 2010] [error] (20014)Internal error: DBD: failed to prepare SQL statements:
[Tue May 25 22:41:19 2010] [error] (20014)Internal error: DBD: failed to initialise
[Tue May 25 22:41:19 2010] [error] [client x.x.x.x] Failed to acquire database connection to look up user 'user@some.domain.com:Domain', referer: [w2.domain.com...]