Forum Moderators: phranque

Message Too Old, No Replies

Another RewriteRule Question

         

MegaWhizz

5:43 am on Mar 25, 2005 (gmt 0)

10+ Year Member



Hello people,

After browsing through the forum, I was able to find most of my answers - but am running into a peculiar problem now.

Here's what I need. I have domain.com and www.domain.com pointing to the same webspace, so I need all URLs with [domain.com...] to get redirected to [domain.com...] This was simple enough using the examples posted here.

One directory under the root folder, however, contains SSL files only. So I set up another redirect to change all http:// requests without server port 443 to turn into https:// requests.

e.g.

[domain.com...] becomes [domain.com...]
Also [domain.com...] becomes [domain.com...]

Also, once users browse OUT of the /dir/ directory the SSL is dropped, so any requests in other directories using port 443 are changed to "normal" requests.

Here are the .htaccess files:

/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteRule (.*) [domain.com...] [R=301,L]
ReWriteCond %{SERVER_PORT} 443
ReWriteRule (.*) [domain.com...] [R=301,L]

/dir/.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*) [dom.com...] [R=301,L]

However now I am getting internal server 500 errors whenever I try to access pages securely, in any directory. The domain to www.domain redirection seems to work fine.

Anybody see what error(s) I am making?

Thanks,

MW

jdMorgan

7:22 am on Mar 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MW,

Welcome to WebmasterWorld!

The best thing to do in these cases is often to check your server error log. Useful messages are written there for many 500-Server Error problems.

Your solution may be prone to problems depending on the setting of RewriteOptions inherit. To avoid this, here's how I'd code this (all in root .htaccess):


RewriteEngine On
# Added - Check for blank Host from HTTP/1.0 client to prevent redirection loop
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Case: Requested Port 443 and not /dir/
RewriteCond %{SERVER_PORT} ^443$
# Added - Check for NOT ssl_dir URL-path prefix
RewriteCond $1 !^dir/
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Case: Requested /dir/ but not on port 443
# (Moved and modified from /dir/ .htaccess)
RewriteCond %{SERVER_PORT} !^443$
# Added - Check for ssl_dir URL-path prefix
RewriteRule ^dir/(.*) https://www.example.com/dir/$1 [R=301,L]

I'm not sure... None of this may help, but it "flattens" the overall design into one file and may be easier to test.

Jim

MegaWhizz

1:09 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



Thanks for the quick reply. And the flatter design does look better :-)

Unfortunately, doesn't work any better. The redirection works, but any attempts at https:// URLs (in the root or sub-directory) trigger "500 Internal Server Error"

Funny thing is the logs don't seem to show the error. Will investigate.

MW