Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: .htaccess / redirect to 'www.'

  1. #1

    .htaccess / redirect to 'www.'

    I have a website that i'm currently building and both its main addresses, i.e. with 'www.' and without open up seperately, i.e. there is no redirection.
    I wish to keep the 'www.' one and redirect the 'non-www.' to the 'www.', what code/commands do i have to add to the .htaccess file?
    Thanks

  2. #2
    Do you have cPanel? You can go to 'redirect' and redirect your domain without www to your domain with WWW. At least that's how I do it

    Greetz
    |Nico Lawsons

  3. #3
    I use this one

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    does the job nicely

  4. #4
    Actually i want to do it with htaccess. My site is on Joomla, after renaming the htaccess.txt to .htaccess i added the following code to the end :

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    Am unsure if its right. Doesn't seem to work, checked multiple sites and all have different variations of code which ultimately does the same thing.

    Can some1 give me the code what they are using for this redirection on their site?
    Thanks.

    Edit : @ Aziz, didn't see your post before typing out this. Anyways thanks

  5. #5
    Was reasearching a bit using Google and found the following variations of code :

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
    </IfModule>
    Code:
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC] 
    RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^yuordomain\.com
    RewriteRule ^(.*)$ http://www.yuordomain.com/$1 [R=permanent,L]

    Currently using the second one, lets c if it works.

  6. #6
    2nd one didn't work, Currently using the third one and it works just fine

  7. #7
    I use the following in the .htaccess in my web's root folder:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^yourdomain\.com$
    RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
    I avoid the !www type rewrite conditions because they can sometimes lead to issues w/ subdomains depending on how they are implemented.

  8. #8
    FYI, this is the one I finally settled on (after a bit of searching around):

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ [NC]
    RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=301,L]
    Works pretty good for me (but yeah, perhaps subdomains would break)!

  9. #9
    I added this today and it seems to work fine:

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$
    RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
    what does this do?

    Code:
    Options +FollowSymLinks
    note: when you replace this, dont use masked URL. thanks ~ admin

  10. #10
    Quote Originally Posted by sachin410 View Post
    what does this do?

    Code:
    Options +FollowSymLinks
    If a directory is symbolically linked in Linux, then +FollowSymLinks tells Apache to obey them. Sym links are basically shortcuts. For example, if /home/username/www is symbolically linked to /home/username/public_html (both are the same directory) then Apache will allow either path to work for various requests.

Page 1 of 2 12 LastLast

Similar Threads

  1. .htaccess All Page Redirect
    By ProxySites.ca in forum Managing
    Replies: 7
    Last Post: 28 May, 2010, 22:52 PM
  2. .htaccess
    By dodolls in forum Managing
    Replies: 6
    Last Post: 15 November, 2009, 07:58 AM
  3. .htaccess help needed - dynanmic redirect
    By DomainMagnate in forum Programming
    Replies: 13
    Last Post: 27 September, 2009, 11:52 AM
  4. .htaccess help
    By Sami4u in forum Building
    Replies: 3
    Last Post: 14 September, 2009, 13:47 PM
  5. .htaccess - How to properly redirect a domain?
    By Shenron in forum Programming
    Replies: 10
    Last Post: 9 January, 2009, 09:30 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
  •