Magento Expert Forum - Improve your Magento experience

Results 1 to 3 of 3

How to use .htaccess to redirect www to non-www?

  1. #1
    Moderator speed2x's Avatar
    Join Date
    Mar 2013
    Location
    Hollywood, Florida, United States
    Posts
    88
    Thanks
    8
    Thanked 7 Times in 6 Posts

    Cool How to use .htaccess to redirect www to non-www?

    I wanna share you guy this code, it 's very useful for me

    Here are the rules to redirect a www URL to no-www:

    Code:
    #########################
    # redirect www to no-www
    #########################
    
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
    Here are the rules to redirect a no-www URL to www:

    Code:
    #########################
    # redirect no-www to www
    #########################
    
    RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
    RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
    Hope it help

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Feb 2015
    Posts
    74
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default

    This is nice code for redirection.

  3. #3
    New member
    Join Date
    Jun 2015
    Location
    Targu Jiu
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    +1, it works

Similar Threads

  1. Replies: 1
    Last Post: 14-03-2019, 07:26 AM
  2. Protect a Directory Using .htaccess
    By david in forum PHP programming
    Replies: 1
    Last Post: 14-03-2019, 07:23 AM
  3. 30 Popular .htaccess code snippets
    By david in forum Programming & Development
    Replies: 4
    Last Post: 14-12-2018, 03:04 AM
  4. Permanent Redirect for 404 error
    By shoaibmarfatiya in forum Magento SEO technique
    Replies: 6
    Last Post: 02-03-2015, 09:46 AM
  5. How to redirect Magento to open through www
    By david in forum Programming & Development
    Replies: 0
    Last Post: 19-03-2013, 04:36 AM

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
  •