Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    68
    Thanks
    3
    Thanked 5 Times in 4 Posts

    rewrite www to non-www

    Could someone please let me know the proper way to do a 301 redirect from www.example.com -> example.com?

    This is for Apache 2.2.x using vhosts (not .htaccess)

    Thanks!

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    I'm not 100% on vhosts but give this ago hopefully this will work.

    Code:
    RewriteEngine on 
    # 
    RewriteCond %{HTTP_HOST} ^www\.(([^.]+\.)+([^.]+)) 
    RewriteRule ^/(.*)$ [%1...] [R=301,L] 
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Location
    www.techmafia.org
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    its called to force no-www if i am write

    you can use this

    PHP Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond 
    %{HTTP_HOST} ^www.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L] 

  • #4
    New Coder
    Join Date
    Jan 2010
    Posts
    68
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Thanks guys!

  • #5
    New Coder
    Join Date
    Jan 2010
    Location
    NYC
    Posts
    46
    Thanks
    1
    Thanked 1 Time in 1 Post
    One other thing, it took me a day to figure this out. I had the same issue and had this command in my htaccess file but it wasn't taking it. I went to the httpd.conf file and changed the override command to all instead of none. Restarted the server and voila, it worked.
    When I wake up I see differently
    Laptop Repair NYC property management software


  •  

    Posting Permissions

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