Wordpress .htaccess Help

Discussion in 'WordPress' started by That-Guy, Aug 29, 2010.

  1. #1
    I am trying to setup a simple re-direct for my Wordpress Blog in my .htaccess file.

    What I want is if people visit:

    mydomain.co.uk
    Code (markup):
    they get re-directed to:

    www.mydomain.co.uk
    Code (markup):
    Has anyone got this working?

    Thanks in Advance :)
     
    That-Guy, Aug 29, 2010 IP
  2. bhuthecoder

    bhuthecoder Member

    Messages:
    245
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    43
    #2
    wp-admin/options-general.php

    change the "Site address (URL)" option located in Setting==>General (in wp admin panel)
     
    bhuthecoder, Aug 29, 2010 IP
  3. That-Guy

    That-Guy Peon

    Messages:
    452
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That is already correct (with www.) but it still allows access without.

    Any other ideas?
     
    That-Guy, Aug 30, 2010 IP
  4. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #4
    Think this is what you're looking for.

    RewriteEngine on
    Options +FollowSymLinks
    RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
    Code (markup):
     
    mcfox, Aug 30, 2010 IP
  5. That-Guy

    That-Guy Peon

    Messages:
    452
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks, has this been tested with Wordpress? The code I tried works fine with basic websites but not with Wordpress.
     
    That-Guy, Aug 30, 2010 IP
  6. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #6
    tbh, I hadn't tried it with Wordpress. No, it doesn't work.

    What about some of these plugins - maybe one of them will do the job you want?
    http://wordpress.org/extend/plugins/tags/canonical
     
    mcfox, Aug 30, 2010 IP
  7. extremephp

    extremephp Peon

    Messages:
    1,290
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Just use A Plugin Called "Redirection" !! That seems to be a powerful one!!

    But, One or the other way, some one will be bringing out the correct Htaccess Code here :D

    ~ExP~
     
    extremephp, Aug 30, 2010 IP
  8. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #8
    I was nearly right. This was bugging me. :)

    Here's the code for Wordpress (tested btw). You need to replace the existing block of Wordpress code in your htaccess file with code below.

    Redirect www.domain to non-www.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$ [NC]
    RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    Code (markup):
    and for non-www to www.domain


    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    Code (markup):

    OR

    If you are comfortable editing the htaccess, just add the two lines under RewriteEngine On to the existing code.

    These:
    or these (depending on whether you want www. or not) see above:
     
    Last edited: Aug 31, 2010
    mcfox, Aug 31, 2010 IP