SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help - problem with www.domain.com => domain.com

    Hi All,

    I thought this was pretty straightforward, but apparently I got something real wrong.

    The rewrite below is supposed to redirect all www prefixed urls to zvis.com domain, including and preserving subdomains.

    RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?zvis\.com)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L,QSA]

    Now, somehow the only timethisrule works is when I access www.zvis.com

    if there is anything after .com, i.e any other file or directory it doesn't fire.
    E.g. http://www.zvis.com/dep/dep.shtml never gets redirected to http://zvis.com/dep/dep.shtml
    I've checked HOST parameter in the GET query headers, it's www.zvis.com, so why the rule isn't working for anything other than www.zvis.com?
    Have Fun,
    Gator
    zknives.com

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Hi Zvi!

    mod_rewrite IS very straightforward and what you got wrong is that your code is ONLY designed to strip the www from the URI. Do you have both the non-www and the www version allowed by your host (because your code should work as you expect)?
    Code:
    RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?zvis\.com)$ [NC]
    # RewriteRule ^(.*)$ http://%1/$1 [R=301,L,QSA]
    # the following will do the job just as well and is easier to understand
    # QSA is automatic UNLESS you're creating a new query string
    RewriteRule .? http://%1/%{REQUEST_URI} [R=301,L]
    You should be able to tell about the host if you can see the DNS records - otherwise, ask them to enable the non-www version of your domain.

    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

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dave!

    [quote=dklynn;4489339Do you have both the non-www and the www version allowed by your host
    ...

    You should be able to tell about the host if you can see the DNS records - otherwise, ask them to enable the non-www version of your domain.
    [/quote]
    I'm maintaining dns records myself. So, I guess I am missing something but what? in dns I can see records for @ and www as A type... Anything else I should have?
    Have Fun,
    Gator
    zknives.com

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Zvi,

    In my DNS record, I have my domain name, 14400, IN, A and my IP address. Following that, I have www, 14400, IN, CNAME, my domain name. Those are the relevant settings in my WHM DNS panel. If you're using your own VirtualHost file, include the non-www'd domain name in the declaration.

    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

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do have both in virtual host, i.e.zvis.com as a server name and www.zvis.com as serveralias.

    In dns records though I don't have anything like 14400 or IN?
    Just @ with ip and www with ip..
    Have Fun,
    Gator
    zknives.com

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Zvi,

    Bummer! What about your hosts file? Does it accept zvis.com?

    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

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I sortta found a reason, but I don't understand why.
    In the child directory which refuses to redirest www to non www there is another .htaccess.
    In that htaccess I have other local redirect rules. But they're irrelevant since,
    even if I put just these 2 lines in the child dir .htaccess
    RewriteEngine on

    RewriteEngine Off

    www doesn't get redirected anymore... I thought top level was processed first?
    Have Fun,
    Gator
    zknives.com

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Zvi,

    The top level IS processed first so you are correct. By the time the subdirectory's .htaccess is parsed, the redirection should already have been made.

    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

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's the weird part, in theory lower level .htaccess should have no effect but it does...
    Have Fun,
    Gator
    zknives.com


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
  •