Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite domain.com to www.domain.com not working

a cry for help

         

oddysey

8:53 pm on Jul 27, 2007 (gmt 0)

10+ Year Member



I've been trying to do a simple mod_rewrite from mydomain.com to www.domain.com. I've done everything short of sacrificing one of my co-workers to the web gods, and nothing seems to work. What does work is if my .htaccess file is something like this:

RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.anythingelse.com/$1 [R=permanent,L]

I actually redirected anyone coming to my site to google.com as a test to see if the mod_rewrite was even working, and it actually worked. But what I want to get to work is something like this:

RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,L]

Finally, I turned on the rewritelogs feature, and I think I've noticed the problem, although I don't have any idea what is causing it, or how to be rid of it. In the logs you can see, among other things, the "input" and you can see where it is tested to see if it matches the pattern you've set in the condition line. Throughout all the logs, I never could find an instance where the input was simply mydomain.com, it was always www.mydomain.com. I explicitly used http://mydomain.com when testing, but again, it never appears in the logs. Sorry for the extreme detail, but I'm about to have a nervous breakdown if I can't get this to work soon. I appreciate any and all advice. Thanks in advance.

-dumbstruck

[edited by: jdMorgan at 10:56 pm (utc) on July 28, 2007]
[edit reason] De-linked [/edit]

g1smd

9:02 pm on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Both of those pieces of code should work as far as I can see.

Have you got this before your Rewrite rules:

Options +FollowSymLinks
RewriteEngine on

oddysey

3:19 am on Jul 28, 2007 (gmt 0)

10+ Year Member



I do actually. I finally figured it out. Like an idiot I was only navigating to the page from a computer that was on the same internal network as the web server. Once I got home, and decided I couldn't sleep without giving it another shot I happened to try it from a my home pc, and it worked like a charm. Wouldn't you know it, the moment I'm ready to give up the solution falls in my lap by accident. Thanks for the help.