Www. version of the website is not working

Hello everyone,
I noticed today that my www. version of the website is really messed up, like no styles / images are loaded at all.

Take a look at that one:
www.petpal.co.il

While the http:// version of the website does works:

What could cause such an issue? any ideas?
I’m thinking it could be caused by htaccess but thats just a wild guess, so ill show my htaaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# redirect old domains to new one
RewriteCond %{HTTP_HOST} ^pet-pal.co.il$ [OR]
RewriteCond %{HTTP_HOST} ^www.pet-pal.co.il$ [OR]
RewriteCond %{HTTP_HOST} ^sospets.brinkster.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.sospets.brinkster.net$
RewriteRule (.*)$ http://petpal.co.il/$1 [R=301,L]

# redirect sub domains
RewriteCond %{HTTP_HOST} ^(.*)\\.petpal\\.co\\.il
RewriteRule ^(.*)$ /orgs/%1/$1 [L,NC,QSA]

# remove .php extension and querystrings from files
RewriteRule private/([a-zA-Z]+)\\-([0-9]+)$ private/$1.php?page=$2 [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule private/([a-zA-Z]+) private/$1.php [L]
RewriteRule ([a-zA-Z]+)\\-([0-9\\-]+)$ $1.php?page=$2 [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ([a-zA-Z]+) $1.php [L]

Thanks,
Ulthane.

You need a rule for redirecting your www URL to your non-www URL.

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

but why is that? why the www. version is not working?

well i managed to find a solution by changing this rule:

RewriteCond %{HTTP_HOST} ^(.*)\\.petpal\\.co\\.il
RewriteRule ^(.*)$ /orgs/%1/$1 [L,NC,QSA]

to this:

RewriteCond %{HTTP:Host} ^(?:klavlove\\.petpal\\.co\\.il)?$
RewriteRule (.*) /orgs/klavlove/$1 [NC,L,NS]

But now i have to make a seperate rule for every sub domain so im still wondering if there’s a better solution.

Yes, create www records in your domain name server. Actually, most hosting accounts are setup to do that for you so I’m surprised that you’re having this problem.

Regards,

DK

according to my host’s instructions i gotta do that through htaaccess, so i would like to see an htaaccess solution please.

ulthane,

If that was your host’s response, change to a better host (the good ones abound … but so do ones like yours).

Sub domain names can only be created by DNS records, never by .htaccess. .htaccess files can redirect visitor requests (from one subdomain to another) but that was not your question. If example.com is working and www.example.com is not (I must assume that you’ve NOT written code to redirect because your www.example returns an error), then the DNS record for www does not exist.

Regards,

DK

hey dklynn,
I think there’s abit of misunderstanding here :slight_smile:
Now my www. version is also working, it was an htaaccess rule that broke it.

this htaaccess rule:

RewriteCond %{HTTP_HOST} ^(.*)\\.petpal\\.co\\.il
RewriteRule ^(.*)$ /orgs/%1/$1 [L,NC,QSA]

the above rule is used to redirect any subdomain to its folder (like a.example.com to example.com/a, b.example.com to example.com/b and so on)
I removed the above htaaccess rule and the www. domain is working fine but now i need to find a new htaacces rule to redirect subdomains to their foldiers, without breaking my www. version of the site.

currently i use this, but i need to repeat it for every sub domain i got:

RewriteCond %{HTTP:Host} ^(?:klavlove\\.petpal\\.co\\.il)?$
RewriteRule (.*) /orgs/klavlove/$1 [NC,L,NS]

hope its more understandable now :slight_smile:
Thanks for your help,
ulthane.

The problem likely was that your subdomain rule was rewriting www.petpal.co.il to www.petpal.co.il/orgs/www/

You should be able to solve this just by adding one more rewrite condition. You want to rewrite all subdomains unless the subdomain is “www”.

RewriteCond %{HTTP_HOST} ^(.)\.petpal\.co\.il
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.
)$ /orgs/%1/$1 [L,NC,QSA]

thanks, that works :slight_smile:

Another approach is without modifying .htaccess , just set DNZ zone and add www as a CNAME, pointing to yur site’s IP address or URL. If you’re on cPanel, go to Domains -> Advanced DNS Zone Editor and add www.yourdomain.com. in Name field, Type CNAME , Address - yourdomain.com

That should work.