SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble redirecting non www urls to www

    I'm trying to make non www urls to my site redirect to www urls. When I place the command below (replacing mysite.com with my actual domain of course) in the .htaccess my site cannot be accessed at all.

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

    My hosting service told me to try this one and it caused a 500 error.

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mysite.com[nc]
    RewriteRule ^(.*)$ http://www.mysite.com/$1 [r=301,nc]

    Any ideas on what could be causing this?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,171
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Try this:

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

  3. #3
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Try this:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
    RewriteRule .? http://www.mysite.com%{REQUEST_URI} [R=301,L]
    You are a genius! You just did what my hosting provider couldn't do in two days and several attempts. Thank you very much.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,171
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by wiseguy View Post
    You are a genius!
    Ha ha, no, I'm a copy-pasta dolt. I just copy the code the geniuses like @dklynn around here post. But glad to be of assistance.

  5. #5
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Ha ha, no, I'm a copy-pasta dolt. I just copy the code the geniuses like @dklynn around here post. But glad to be of assistance.
    If that's true then my hosting provider should hire some "copy-pasta dolts".

    Thanks again.

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,171
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by wiseguy View Post
    If that's true then my hosting provider should hire some "copy-pasta dolts".
    Yes, perhaps email them and suggest they sign up to a forum.


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
  •