Forum Moderators: phranque
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]
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
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?
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
I double checked the space, still error.
Btw (here newbieness goes lol), 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
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]
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]
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]
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.
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
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]