SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    301 Redirect problem

    I want to redirect all requests beginning with www to the same pages without the www.

    I've tried the 301 redirect code that cPanel creates, and code from another SitePoint member. Both have the same result: In one directory, most pages are not redirecting. Other directories, and top level pages *are* redirecting, and the redirects show as search engine-friendly.

    Here's the current .htaccess file:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

    ErrorDocument 400 /index.htm
    ErrorDocument 401 /index.htm
    ErrorDocument 403 /index.htm
    ErrorDocument 404 /scripts/404.htm
    ErrorDocument 500 /index.htm

    My domain is on a hosted, shared Apache server running Linux. If you can think of any other details that might be helpful, please let me know. Thanks!

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

    A new thread to continue? Oh, well ...

    You're saying that the code is working in some directories but not others. Are these test URIs in the same domain? If the above code (the ErrorDocument lines have no impact on the mod_rewrite code) is in the DocumentRoot of the domain, it will redirect ALL requests to that domain. Therefore, I've got to ask about the domains you're using and the physical paths (relative to each other) of your test URIs.

    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
    Jan 2012
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for following me to the new thread, DK. That was sweet of you.

    The domain for all the directories and pages is the same. The site is 15 years old, so we've gathered up quite a few links to www.example.com. However, we now use example.com as our canonical form.

    Basically, since Google sees the www and non-www links as two separate pages, I'm afraid that we're not getting the benefit of those many thousands of links in, and may even have been penalized. The 301 redirect seems to be the preferred method for dealing with this issue.

    The content within the head of the webpages is the same for the pages that are redirecting properly, and the ones that aren't. I've also now found some pages within the problematic directory that are redirecting properly, but there are very few of them. So this is problem is hard to pin down.

    I'm going to send you a private message with some sample links, to see if you can figure out anything. If you don't want to mess with it, just ignore the message. Thanks!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    SOLVED, thanks to dklynn!

    It turns out that a wayward tech support guy had added a second .htaccess file to my sub-directory that was having problems. I deleted the file, and all is well now.

    Hope this helps someone else!

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

    You'd better be a "hot babe" if you're calling me "sweet!"

    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 Enthusiast
    Join Date
    Jan 2012
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Oops! Just saw this. Would "aging babe" be alright?

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

    At my age, I can't be choosey so, if the "hot" still applies, "aging babe" would be fine!

    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 Enthusiast
    Join Date
    Jan 2012
    Posts
    42
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    LOL! Now, now, Mr. Devil.

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


    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


Tags for this Thread

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
  •