SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    635
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    HTaccess Redirect Good For Only One Page?

    Sitepoint members,
    I just learned from my webhost that when code like this
    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]

    was put in my htaccess (and I used it for other sites) it only works for the home page. My webhot didn't know of a way to remove www for all pages with one chunk of code that applies to all pages. I would think that in all the programming going on over the last 10 years and with the global nature of the htaccess file that this problem would have been solved. This seems to be a big hole in the possibility for life without www. Maybe not, I found a well known website where you can add www to any of their web address, hit enter, and the www will be removed form the address field. What is the htaccess code to do this, or do you think the site actually has code in their htaccess address by address for every one of their pages?

    Thanks,

    Chris

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,277
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chris77 View Post
    My webhot didn't know of a way to remove www for all pages with one chunk of code that applies to all pages.
    I suppose your webhost also doesn't know how to use Google. My advice: Don't rely on your webhost for any more htaccess code. They don't seem to be good at it.

    Fortunately, it's a small and simple change to make it work for all pages.

    Code:
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    "First make it work. Then make it better."

  3. #3
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    635
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Jeff,
    That code worked great. I guess I'm at fault some for not thinking of that simple phrse you used in google. No doubt something is off center somewhat when my webhost didn't know the answer to this common need, even after working on it for a while.

    The computer video via the blue google link was interesting. I never saw anything like that before, other than with an old Lotus program. How did you do that?

    Thanks Jeff

  4. #4
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    635
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Maybe it's discouraged because it uses more processing power.


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
  •