Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem with https address

mod rewrite problem with https address

         

bendj

10:38 pm on Aug 1, 2004 (gmt 0)

10+ Year Member



Below is what I have so far.
Here is the problem:
I also noticed that if I use the htaccess file below and I try to access something like
[maindomain.com...]
I get an internal server error.
NOTE - that the above URL is to a secure server (SSL) is there a condition I need to put in there so it knows what to do with the HTTPS?

RewriteEngine on
0 #Take anything other than main domain, and direct it to maindomain.com
1 RewriteCond %{HTTP_HOST}!^www.maindomain.com$ [NC]
2 RewriteCond %{REQUEST_URI}!^/robots\.txt$
3 RewriteRule (.*) [maindomain.com...] [R=301]
4
5 #If robots.txt is requested from anything other than maindomain send new txt file.
6 RewriteCond %{HTTP_HOST}!^maindomain\.com
7 RewriteRule ^robots\.txt /robots_noindex.txt [L]

jdMorgan

11:26 pm on Aug 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bendj,

Welcome to WebmasterWorld [webmasterworld.com]!

If you are accessing via https, the Hostname will probably have port 443 appended (www.example.com:443). Therefore, your first rule will always be invoked, and you will get a loop -- you can verify this in your error log.

Do not end-anchor RewriteCond %{HTTP_HOST} patterns!

Jim

bendj

12:28 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Jim.. Thanks for the welcome, thanks for the help.

I changed:
RewriteCond %{HTTP_HOST}!^www.maindomain.com$ [NC]

To:
RewriteCond %{HTTP_HOST}!^www.maindomain.com [NC]

Getting rid of the end anchor and am getting the same internal error. Please note I'm very new to this, getting used to some syntax :) So if you see any syntax errors or a better way to code it let me know. I'm guessing I have to tell it how to distinguish between a http and a https request. I guess this is what I do not know how to do.

Is this what you meant?

jdMorgan

1:31 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure you have a space before "!":

RewriteCond %{HTTP_HOST} !^www.example.com [NC]

HTTP_HOST for an http request will look like "www.example.com" or "www.example.com:80", whereas an https request will look like "www.example.com:443".

If you work through your original rewrite logic with "www.example.com:443" as the value of HTTP_HOST, you'll see that it leads to an "infinite" rewrite loop -- the domain name will be correct, but the rule will always redirect because you are requiring it to not have a port number appended, and for https, it will always have ":443" on the end.

If you already had the space in your code, and you still get an error, then examine your server error log and see what it says. That will help you (and us) figure it out.

Jim

bendj

1:49 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Ok i understand the https request is going to look have the different port on it. So doesnt there need to be a condition in there saying "if https port, then do something different"? Basically I have an /order/ directory. I want this to be secure (https). So when a https request is made I want it to stay a https request and not be rewritten.

I double checked the space, still error.

Btw (here newbieness goes lol), where can i find the server error log?

jdMorgan

2:13 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> where can i find the server error log?

Ask your host -- the location and access method vary widely across hosting companies.

> So doesnt there need to be a condition in there saying "if https port, then do something different"?

Yes, if that is what you want to do, you'll need another ruleset to do it. I suggest you get rid of your server error first, though...

If you don't have this already, add Options +FollowSymLinks ahead of your RewriteEngine on directive. This option must be enabled for mod_rewrite to work, either in httpd.conf or in your .htaccess.

Jim

bendj

2:29 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Ok this is what I have in .htaccess
Still trying to find the error log.

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteCond %{REQUEST_URI} !^/robots\.txt$
RewriteRule (.*) [example.com...] [R=301]

RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule ^robots\.txt /robots_noindex.txt [L]

[edited by: jdMorgan at 2:46 am (utc) on Aug. 2, 2004]
[edit reason] Removed specifics per TOS [/edit]

bendj

2:43 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Is it going to be the same thing as an access log?

jdMorgan

2:47 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try it and see...

bendj

2:53 am on Aug 2, 2004 (gmt 0)

10+ Year Member



This seems to be showing when the error comes up.
When I type in [domain.com...]

The livesupport thing is a monitor I have on the site, dunno why its in there, i guess its one of the first thing it tries to load. I removed the script for that and it still gives the error.

207.206.144.21 - - [01/Aug/2004:21:06:58 -0400] "GET /home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/home/username/domain-www/www.domain.com/home/username/domain-www/
www.domain.com/support/livesupport/livehelp_js.php?cmd=hidden&department=1 HTTP/1.1" 301 2368 "http://www.domain.com/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"

[edited by: jdMorgan at 3:11 am (utc) on Aug. 2, 2004]
[edit reason] Fixed side-scroll [/edit]

bendj

3:14 am on Aug 2, 2004 (gmt 0)

10+ Year Member



It seems its still looping somehow?

jdMorgan

3:21 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bendj,

Your server is obviously stuck in a redirect loop. It looks to me like you have a server configuration problem. I strongly suggest you rip out all of your .htaccess rewriterules, except for the following simplified version of your first rule, and then ask your host why it won't work. Something in the server config is not quite right -- It could be something like an incorrect ScriptAlias or DocumentRoot, a domain-name rewrite in httpd.conf that conflicts with this one (i.e. rewriting the www- domain back to the non-www- domain), or something more complicated and beyond my ability to diagnose from afar.


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim

bendj

3:50 am on Aug 2, 2004 (gmt 0)

10+ Year Member



Yeah still not working :(

It works with all other http requests just not https for some reason.

Well ok i will try to contact my host.
Is there something temorarily I can enter that will detect the https and do nothing with it?

jdMorgan

6:13 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You mean suppress the domain rewrite for https?

For the rule I posted above, just add


RewriteCond %{HTTP_HOST} !example\.com:443 [NC]

ahead of the existing RewriteCond (yes, omit the www and the start anchor as shown)

Jim

bendj

1:54 pm on Aug 2, 2004 (gmt 0)

10+ Year Member



Strange,

Still getting the error even with this extra line of code. I'm still waiting on a reply from the host.
I have seen a condition like RewriteCond %{HTTPS}.
Does this have anything to do with any of my problems?

This server problem isnt helping my htaccess learning experience much :)

Thanks again for the help.

bendj

3:54 pm on Aug 2, 2004 (gmt 0)

10+ Year Member



Could this have anything to do with the version of apache running?

bendj

8:41 pm on Aug 2, 2004 (gmt 0)

10+ Year Member



Ok when I get this error this is what I get:
By the way, errors are showing up for http requests but not https. Do I need to tell my host to do some type of error log for https?

Any ideas?

SSL Request Log:
[02/Aug/2004:16:39:07 -0400] 165.134.117.49 SSLv3 RC4-
MD5 "GET / HTTP/1.1" 630

Not seeing anything in the error log even though it is a 500 internal server error.
Apache/1.3.29 Server at domain.com Port 443

jdMorgan

9:44 pm on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bendj,

Just broke free for a minute...

Add this line to what you have now, and see if it helps:


RewriteCond %{SERVER_PORT} !^443$

Leave the other RewriteCond we added in place for now.

Jim

bendj

9:52 pm on Aug 2, 2004 (gmt 0)

10+ Year Member



Jim,

This is what I have, still error. Im trying to get my host to turn on error logging fot https. It works for http but errors arnt being logged for https it seems.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} !domain\.com:443 [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) [domain.com...] [R=301,L]

bendj

6:49 pm on Aug 3, 2004 (gmt 0)

10+ Year Member



Here is what I get from the error log.
Keep in mind it works for HTTP request, but not HTTPS.

[Tue Aug 3 14:48:18 2004] [alert] [client 165.134.117.49] /home/username/www/.htaccess: Invalid command 'RewriteEngine',
perhaps mis-spelled or defined by a module not
included in the server configuration

jdMorgan

10:27 pm on Aug 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> defined by a module not included in the server configuration

Check the server config for https - It looks like mod_rewrite.so isn't defined for https for some reason.

Jim

bendj

10:37 pm on Aug 3, 2004 (gmt 0)

10+ Year Member



Jim,

My host gave me access to the /etc/httpd/httpd.conf file but it was only fille of <Virtual Host> information, I did not see any of the regular configuration. Would this be somewhere else?