Forum Moderators: phranque
I do not know why I get a 400-Bad Request for SSL requests, and I do not know how to find out. I don't even know if it matters why, or is it enough to know that I am, and now I simply need to fix it?
What is my solution?
#1 To get a custom 400 page to return a 400 header?
#2 To rewrite the www.mysite.com:443 to www.mysite.com?
If #1. I can get ErrorDocument 400 to work to a custom page, but it still returns a 200 header. I cannot get it to return a 400 header. But I don't think this is my overall solution anyway, so I don't think it is important for me to address this as I have no other use for a custom 400 page...
So, I am assuming my goal is #2 to rewrite www.mysite.com:443 to www.mysite.com. And I am having problems intercepting the 443 part of the URL...
For testing purposes only, to confirm I am using Rewrites that work, I have tried to set up conditions whereby URLs on my site get redirected to google.com for my IP. Just for testing, and to restore my sanity that I have the mechanics of this working...
Note: I have disabled my cache. My rewrite code is not in a <Directory> container in either httpd.conf or ssl.conf, but inside ssl.conf's <VirtualHost _default_:443> container and httpd.conf's <VirtualHost *:80> container.
* in httpd.conf only!
RewriteCond %{REMOTE_ADDR} ^#*$!\.#*$!\.#*$!\.#*$!.*
RewriteRule ^ [google.com...] [R=301,L]
-> for my IP, for any page on my site, I am sent to google.com.
-> Thus, I know my httpd.conf works with Rewrites.
-> Still, www.mysite.com:443 brings up standard 400 Bad Request page
* in httpd.conf only!
RewriteCond %{REMOTE_ADDR} ^#*$\.#*$\.#*$\.#*$.*
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^ [google.com...] [R=301,L]
-> nothing gets sent to google, neither http nor https requests
-> Still, www.mysite.com:443 brings up standard 400 Bad Request page
* in ssl.conf only!
RewriteCond %{REMOTE_ADDR} ^#*$\.#*$\.#*$\.#*$.*
RewriteCond %{SERVER_PORT} =443
RewriteRule ^ [google.com...] [R=301,L]
-> http requests are fine, https requests get sent to google!
-> Thus, I know my ssl.conf works with Rewrites.
-> And still, www.mysite.com:443 brings up standard 400 Bad Request page
In none of the tests above, will www.mysite.com:443 get sent to google.com.
So, now back to just my site, and some rewriterules...
RewriteCond %{HTTP_HOST} :443$
RewriteRule ^/(.*)$ [mysite.com...] [R=301,L]
-> added to both httpd.conf and ssl.conf
-> doesn't work
-> www.mysite.com:443 brings up standard 400 Bad Request page
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/(.*)$ [mysite.com...] [R=301,L]
-> added to both httpd.conf and ssl.conf
-> doesn't work
-> www.mysite.com:443 brings up standard 400 Bad Request page
+++++
My header always looks like this:
[mysite.com:443...]
GET / HTTP/1.1
Host: www.mysite.com:443
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 65535
Connection: keep-alive
Cache-Control: max-age=0
HTTP/1.x 200 OK
+++++++++++
In a previous thread, jdMorgan said "So, if you have other directives that will affect requests for "/.*" URL-paths, these may be executing before your rewriterule ever has a chance to execute, and making it appear that the rule "doesn't work."
I am doing many other rewrites in httpd.conf, though ssl.conf is empty. I am unclear on how to make sure this is not a problem. For example, [example.com...] does rewrite to http://www.example.com.
+++++++++
I would be most grateful for any advice. Probably the only thing I haven't tried over the past 3 weeks is the one thing that will fix this problem for me, but I just can't figure out what that is.
Try:
RewriteCond %{SERVER_PORT} ^443$
RewriteRule .? [google.com...] [R=301,L]
* If you don't get a redirect, try:
RewriteCond %{HTTPS} ^on$
RewriteRule .? [google.com...] [R=301,L]
* If one of those works, try:
RewriteCond %{WHAT_WORKED} ^WHAT_WORKED$
RewriteCond %{REMOTE_ADDR} ^#*$\.#*$\.#*$\.#*$.*
RewriteRule .? [google.com...] [R=301,L]
The 200 rather than 400 error could be one of a few things I can think of:
1.) An ErrorDocument directive which creates an external redirect rather than serving the custom error page internally.
2.) For some reason there's a header set in the script on the custom error page overriding the header.
* The 200 could also be caused by a redirect, if the URL of the page changes is the browser, which you did not state, but IMO it's most likely the first.
<edited x 2>
Changed the Variable in the Condition...
(My fingers were having fun typing and went with the wrong Conditional Variable. LOL. :)
Make sure you empty your browser cache between each coding try.
Removed the $ preceding a rule... Copy / Paste Error.
</edited x 2>
RewriteCond %{HTTPS} ^on$
RewriteRule .? [google.com...] [R=301,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule .? [google.com...] [R=301,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^ [google.com...] [R=301,L]
For the record, right now, my errordocument 400 is commented out, but it looks like this (so it is internal, not external):
ErrorDocument 400 /error/error400.html
And error400.html has no script - it is a very basic HTML file. And when error400.html is invoked, there is no URL redirect in the browser.
No other clues jumped out at me as I tried each of these...
If you don't know, try this in any file you feel like:
RewriteRule .? [webmasterworld.com...] [R=301,L]
(Make sure it's in a test directory or something, because it redirects anything to webmaterworld.com from any directory .htaccess or the httpd.conf. If you don't have both, then turn them on...)
I have been able to do rewrites, no problen... I have the following in my httpd.conf:
<VirtualHost *:80>
ServerAdmin webmaster@mysite.com
ServerName www.mysite.com
DocumentRoot /home/websites/mysite
ErrorLog logs/nossl-2009-error
CustomLog logs/nossl-2009-access common
ServerAlias mysite.com www.mysite.com
ScriptAlias /cgi-bin/ "/home/cgi-bin/mysite/"
RewriteEngine On
<Directory "/home/websites/mysite">
AllowOverride All
Options -Indexes FollowSymLinks
order allow,deny
Allow from all
Options +ExecCGI
</Directory>
The following is correct... There's no + on yours.
Options -Indexes +FollowSymLinks
Also, it's technical, but:
RewriteEngine on
And I usually turn the engine on right before any Mod_Rewrite, in case I need to move it or something. I also don't work in the httpd.conf very much, so I don't want to speculate too much, but will say try what I posted in the .htaccess too and make sure you turn the RewriteEngine on in there again too. (What I posted should work anywhere, because .? matches 0 or 1 character or IOW: any request in either file, because there will always be 0 or 1 character in a request, but try it in an isolated .htaccess file and see if you can get it to work, then you can trouble shoot from there once you get it working.)