SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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:
    http://petpal.co.il

    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:

    Code:
    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.

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    You need a rule for redirecting your www URL to your non-www URL.

    Code:
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    but why is that? why the www. version is not working?

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well i managed to find a solution by changing this rule:
    Code:
    RewriteCond %{HTTP_HOST} ^(.*)\.petpal\.co\.il
    RewriteRule ^(.*)$ /orgs/%1/$1 [L,NC,QSA]
    to this:
    Code:
    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.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by ulthane View Post
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    according to my host's instructions i gotta do that through htaaccess, so i would like to see an htaaccess solution please.

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hey dklynn,
    I think there's abit of misunderstanding here
    Now my www. version is also working, it was an htaaccess rule that broke it.

    this htaaccess rule:
    Code:
    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:
    Code:
    RewriteCond %{HTTP:Host} ^(?:klavlove\.petpal\.co\.il)?$
    RewriteRule (.*) /orgs/klavlove/$1 [NC,L,NS]
    hope its more understandable now
    Thanks for your help,
    ulthane.

  9. #9
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ulthane View Post
    well i managed to find a solution by changing this rule:
    Code:
    RewriteCond %{HTTP_HOST} ^(.*)\.petpal\.co\.il
    RewriteRule ^(.*)$ /orgs/%1/$1 [L,NC,QSA]
    to this:
    Code:
    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.
    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]
    "First make it work. Then make it better."

  10. #10
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks, that works

  11. #11
    Non-Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •