0

On my site, say example.com, if I try to access test.example.com, Firefox automatically adds www. to test.example.com, making it www.test.example.com, which causes an error. However, if I visit a site like my.ebay.com, no www. is added so no error occurs. What's going on?

Just in case, my .htaccess file is as follows:

Options -Multiviews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php

I looked through Firebug and it seems like Firefox doesn't even make an attempt to reach test.example.com before reverting to www.test.example.com.

One nuance I didn't realize until now. If I try to access the site using test.example.com/, the www. is added. If however that trailing slash is not there, then I am sent to the sub domain properly.

4
  • What error do you get?
    – sandradev
    Commented Jun 30, 2012 at 16:17
  • Try pinging the address and see that it actually exists in DNS. Some browsers second guess if test.example.com does not resolve and try adding www for a second attempt.
    – Joachim Isaksson
    Commented Jun 30, 2012 at 16:21
  • I tried pinging the subdomain and I am able to reach it. As for the error I get, it reads "You tried to visit www.test.example.com, which is not loading."
    – user532493
    Commented Jun 30, 2012 at 16:44
  • possible duplicate of Yet Another Mod_Rewrite Issue - Firefox Adds www
    – mario
    Commented Jun 30, 2012 at 20:54

3 Answers 3

1

Have you tried to manually adding the protocol prefix?

http://test.example.com won't get redirected.

Options -Multiviews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www(.*)
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^(.*).example.com/(.*)$ http://$1.example.com/$2 [R=301,L]

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php

In the future, look at this article: http://support.mozilla.org/en-US/questions/714016

5
  • But I'm trying to build a website for others and I don't want them to have to go through that. I just want my site to be like the other millions out there.
    – user532493
    Commented Jun 30, 2012 at 16:31
  • Try the updated htaccess
    – sixeightzero
    Commented Jun 30, 2012 at 16:33
  • That fix would only work for one subdomain, I need it to work for all subdomains.
    – user532493
    Commented Jun 30, 2012 at 16:43
  • Actually, the updated .htaccess doesn't seem to fix it for any subdomains.
    – user532493
    Commented Jun 30, 2012 at 16:53
  • The issue still exists even with that updated .htaccess.
    – user532493
    Commented Jun 30, 2012 at 17:09
0

There's www automatically added in your url because you stated it in your htaccess rule.

Look at this part:

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

That mean to add www to your url when its not present.

2
  • This only matters if the ul just starts with example.com. test.example.com would not match tht rule
    – sixeightzero
    Commented Jun 30, 2012 at 16:35
  • Yeah, if I remove the two lines you quoted from my .htaccess file I still get the error.
    – user532493
    Commented Jun 30, 2012 at 16:38
0

It looks like it was a small glitch or something that was fixed by clearing the browser's history.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.