www vs Non-www, Separate Homepage & Blog

Discussion in 'Apache' started by AidenChong, May 17, 2008.

  1. #1
    Hi there,

    I have a a wordpress blog installed in http://www.example.com/blog/. When I type http://www.example.com/blog/ OR http://example.com/blog/ in my firefox/IE7 address bar, the result will appear as http://www.example/com/blog/. I believe this is what they call , a canonical form of URL (please correct me if I am wrong).

    For my homepage, when I type http://example.com/ in my firefox/IE7 address bar, it will then appear as http://example.com/ . If I type http://www.example.com/ , it will then appear to be http://www.example.com/ . So this is a non-canonical form of URL ?

    I have done some search in DP forum, and came out with several 301 redirect results, but I am not sure which to use.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^whatever/(.*)$ http://www.domain.com/$1/ [R=301,L]
    Code (markup):
    This is the 301 redirect code that I've came up with.

    Question 1 : Should I use this code in my root folder's .htaccess file ?

    Question 2 : If I have decided to add the code above, into my root folder's .htaccess file, will it affect my wordpress blog which was being installed in http://www.example.com/blog/ ?


     
    AidenChong, May 17, 2008 IP
  2. mjewel

    mjewel Prominent Member

    Messages:
    6,693
    Likes Received:
    514
    Best Answers:
    0
    Trophy Points:
    360
    #2
    The code goes in your root htaccess file. Make a back up copy of the one currently on your server and if you have any problems, it will take a few seconds to replace the backup copy.

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

    (this is assuming you want the www.domain.com to always show)
     
    mjewel, May 17, 2008 IP
  3. AidenChong

    AidenChong Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks mjewel . But do I need to add these before the RewriteEngine On code ?
    [Options +Indexes
    Options +FollowSymlinks]
     
    AidenChong, May 17, 2008 IP
  4. mjewel

    mjewel Prominent Member

    Messages:
    6,693
    Likes Received:
    514
    Best Answers:
    0
    Trophy Points:
    360
    #4
    You shouldn't need to add them, but it really depends on your sever configuration. Just try it without it.
     
    mjewel, May 17, 2008 IP
  5. AidenChong

    AidenChong Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks mjewel ! It works well without the additional code which I've mentioned.

    Have a nice day ~ :)
     
    AidenChong, May 17, 2008 IP